Modul:InterviewNavbox: Unterschied zwischen den Versionen
Aus DragonballWiki
Weitere Optionen
Inhalt gelöscht Inhalt hinzugefügt
| (Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
local utils = require('Module:InterviewUtils') |
|||
local p = {} |
local p = {} |
||
local dateParser = require('Module:InterviewUtils') |
|||
-- Initialize caches |
|||
local function cleanIntervieweeName(interviewee) |
|||
local dateRangeCache = {} |
|||
local cleaned = mw.text.trim(interviewee) |
|||
local parsedDateCache = {} |
|||
cleaned = string.gsub(cleaned, '%[%[(.-)%]%]', '%1') -- remove wikitext link |
|||
cleaned = string.gsub(cleaned, '{{W|(.-)|(.-)}}', '%2') -- handle template with piped link |
|||
local function getDateRange(year) |
|||
cleaned = string.gsub(cleaned, '{{W|(.-)}}', '%1') -- remove template |
|||
-- Check if the year's range is cached |
|||
cleaned = string.gsub(cleaned, '%[extlink (.-)%]', '%1') -- remove external link |
|||
if not dateRangeCache[year] then |
|||
cleaned = string.gsub(cleaned, "'", ''') -- replace single quotes with HTML character entity |
|||
local ranges = { |
|||
return cleaned |
|||
{1980, 1995, 1}, |
|||
{1996, 2005, 2}, |
|||
{2006, 2015, 3}, |
|||
{2016, 2020, 4}, |
|||
{2021, 2025, 5}, |
|||
{2026, 2030, 6}, |
|||
} |
|||
for _, range in ipairs(ranges) do |
|||
if year >= range[1] and year <= range[2] then |
|||
dateRangeCache[year] = range[3] -- Cache the result |
|||
break |
|||
end |
|||
end |
|||
end |
|||
return dateRangeCache[year] or nil |
|||
end |
end |
||
function p.main(frame) |
|||
local |
local dateRangeInput = tonumber(frame.args[1]) or 1 |
||
local |
local content = mw.loadJsonData('DragonballWiki:Interviews') |
||
local interviews_table = content.interviews |
|||
local year, _, _ = utils.parse(interview.date) -- get the year from the date |
|||
local list = {} |
|||
local titleGroup = {} |
|||
-- Group interviews by title without date |
|||
local cleanInterviewees = {} |
|||
-- Use caching for date parsing |
|||
for _, interviewee in ipairs(interview.interviewee) do |
|||
for _, interview in ipairs(interviews_table) do |
|||
local cleanInterviewee = cleanIntervieweeName(interviewee) |
|||
local date = interview.date |
|||
table.insert(cleanInterviewees, cleanInterviewee) |
|||
-- Check if the parsed date is cached |
|||
end |
|||
if not parsedDateCache[date] then |
|||
parsedDateCache[date] = dateParser.parse(date) -- Cache the parsed date |
|||
local function valueOrDefault(value, default) |
|||
if value == nil or value == '' then |
|||
return default |
|||
else |
|||
return value |
|||
end |
end |
||
local year = parsedDateCache[date] |
|||
end |
|||
table.insert(output, '<div class="mnbox interview" id="' .. interview.title .. '" data-year="' .. year .. '" data-interviewee=\'' .. mw.text.jsonEncode(cleanInterviewees) .. '\' data-type="' .. interview.type .. '" data-tlstatus="' .. valueOrDefault(interview.translation, 'Complete') .. '" data-trstatus="' .. valueOrDefault(interview.transcript, 'Complete') .. '" data-publication="' .. valueOrDefault(interview.publication, 'None') .. '" data-tags=\'' .. mw.text.jsonEncode(interview.tags) .. '\'>') |
|||
local titleWithoutDate = string.match(interview.title, '^(.-)%s*%(.-%)$') or interview.title |
|||
table.insert(output, '<div class="ivimage" style="display:table-cell; vertical-align:top;">') |
|||
titleGroup[titleWithoutDate] = titleGroup[titleWithoutDate] or {} |
|||
if interview.cover ~= '' then |
|||
table.insert(titleGroup[titleWithoutDate], {interview = interview, year = year}) |
|||
else |
|||
table.insert(output, '[[File:NoPicAv.png|90px]]') |
|||
end |
|||
table.insert(output, '</div>') |
|||
table.insert(output, '<div style="display:table-cell; width:100%;">') |
|||
table.insert(output, '<div class="column">') |
|||
table.insert(output, '<div class="diamond" style="background:' .. frame:preprocess('{{Color|' .. interview.part .. '}}') .. '; text-align:center; padding:0.5%;">') |
|||
table.insert(output, '<span class="fadeinimg" style="float: left; margin-left:5px;">') |
|||
table.insert(output, '[[File:JJLSymbol.png|20px|link=#' .. interview.title .. '|Link to this section]]</span>') |
|||
if interview.display then |
|||
table.insert(output, '<span class="iv-link mcbutton mw-ui-button mw-ui-progressive">' .. frame:preprocess("{{Shadow|{{White2|Interview:" .. interview.title .. "|'''" .. interview.display .. "}}}}") .. '</span>') |
|||
else |
|||
table.insert(output, '<span class="iv-link mcbutton mw-ui-button mw-ui-progressive">' .. frame:preprocess("{{Shadow|{{White2|Interview:" .. interview.title .. "|'''" .. interview.title .. "}}}}") .. '</span>') |
|||
end |
|||
table.insert(output, '</div>') |
|||
table.insert(output, '<div style="padding-left:1%; font-size:90%;">') |
|||
if interview.translation then |
|||
table.insert(output, frame:preprocess('{{Tag|' .. interview.translation .. '}}')) |
|||
end |
|||
if interview.transcript then |
|||
table.insert(output, frame:preprocess('{{Tag|' .. interview.transcript .. '2}}')) |
|||
end |
|||
table.insert(output, frame:preprocess('{{Tag|' .. interview.media .. '}}')) |
|||
table.insert(output, frame:preprocess('{{Tag|' .. interview.type .. '}}')) |
|||
table.insert(output, frame:preprocess('{{Align|{{Tag|Date=' .. interview.date .. '}}|right}}')) |
|||
table.insert(output, '<div class="interviewee" style="display:table-row;">👤 ') |
|||
for i, person in ipairs(interview.interviewee) do |
|||
if i > 1 then |
|||
table.insert(output, ", ") |
|||
end |
|||
table.insert(output, frame:preprocess(person)) |
|||
end |
end |
||
-- Generate list |
|||
table.insert(output, '</div>') |
|||
for _, interview in ipairs(interviews_table) do |
|||
table.insert(output, '<div style="display:table-row;">📜 ') |
|||
local year = dateParser.parse(interview.date) |
|||
local dateRange = getDateRange(year) |
|||
table.insert(output, frame:preprocess('{{Tag|' .. tag .. '}}')) |
|||
end |
|||
table.insert(output, '</div></div></div></div></div>') |
|||
return table.concat(output) |
|||
end |
|||
-- Export the generateInterview function so it can be used from outside the module |
|||
function p.generateInterview(frame) |
|||
-- Extract the interview title from frame.args[1] |
|||
local interviewTitle = frame.args[1] |
|||
-- Load the interviews from JSON data |
|||
local interviewsJson = mw.loadJsonData('DragonballWiki:Interviews').interviews |
|||
if dateRange == dateRangeInput then |
|||
-- Find the interview with the matching title |
|||
local titleWithoutDate = string.match(interview.title, '^(.-)%s*%(.-%)$') or interview.title |
|||
local interview = nil |
|||
local interviews = titleGroup[titleWithoutDate] |
|||
for i, v in ipairs(interviewsJson) do |
|||
local hasMultipleInterviews = #interviews > 1 |
|||
local itemTitle = hasMultipleInterviews and interview.title or titleWithoutDate |
|||
interview = v |
|||
local item = frame:expandTemplate{title = 'INT', args = {interview.title, itemTitle}} |
|||
break |
|||
table.insert(list, '*' .. item) |
|||
end |
end |
||
end |
end |
||
return table.concat(list, '\n') |
|||
-- If we found the interview, generate it |
|||
if interview ~= nil then |
|||
return generateInterview(interview, frame) |
|||
else |
|||
return "Interview not found" |
|||
end |
|||
end |
end |
||
function p.generateArchive(frame) |
|||
local content = mw.loadJsonData('DragonballWiki:Interviews').interviews |
|||
local html = {'<div id="interview-container">'} -- Start the div with the ID 'interview-container' |
|||
for _, interview in ipairs(content) do |
|||
table.insert(html, generateInterview(interview, frame)) |
|||
end |
|||
table.insert(html, '</div>') -- End the div with the ID 'interview-container' |
|||
return table.concat(html) |
|||
end |
|||
function p.generateIndividual(frame) |
|||
-- Extract the interviewee |
|||
local targetInterviewee = mw.title.getCurrentTitle().text |
|||
targetInterviewee = string.gsub(targetInterviewee, "'", ''') |
|||
targetInterviewee = string.gsub(targetInterviewee, "/pl", '') |
|||
-- Load the interviews from JSON data |
|||
local content = mw.loadJsonData('DragonballWiki:Interviews').interviews |
|||
-- Find the interviews belonging to the interviewee |
|||
local interviewsForPerson = {} |
|||
for i, interview in ipairs(content) do |
|||
for _, interviewee in ipairs(interview.interviewee) do |
|||
local cleanedInterviewee = cleanIntervieweeName(interviewee) |
|||
if cleanedInterviewee == targetInterviewee then |
|||
table.insert(interviewsForPerson, interview) |
|||
break |
|||
end |
|||
end |
|||
end |
|||
local output = {} |
|||
if #interviewsForPerson > 0 then |
|||
table.insert(output, '{| class="wikitable sortable" style="font-size:small"') |
|||
table.insert(output, '|-') |
|||
table.insert(output, '! |#|| class="unsortable" |Interview||Type||Media||class="unsortable"|Published') |
|||
for i, interview in ipairs(interviewsForPerson) do |
|||
local displayTitle = interview.display |
|||
local title = interview.title |
|||
table.insert(output, '|-') |
|||
if displayTitle == nil then |
|||
table.insert(output, '|' .. i .. '|| style="color:white; background: {{Color|' .. interview.part .. '}}; text-shadow: 1px 1px 1px #333333;"|{{White2|Interview:' .. title .. '|' .. title .. '}}||{{Tag|' .. interview.type .. '}}||{{Tag|' .. interview.media .. '}}||' .. interview.date) |
|||
else |
|||
table.insert(output, '|' .. i .. '|| style="color:white; background: {{Color|' .. interview.part .. '}}; text-shadow: 1px 1px 1px #333333;"|{{White2|Interview:' .. title .. '|' .. displayTitle .. '}}||{{Tag|' .. interview.type .. '}}||{{Tag|' .. interview.media .. '}}||' .. interview.date) |
|||
end |
|||
end |
|||
table.insert(output, '|}') |
|||
return frame:preprocess(table.concat(output, '\n')) |
|||
else |
|||
return "No interviews found for " .. targetInterviewee |
|||
end |
|||
end |
|||
return p |
return p |
||
Aktuelle Version vom 24. Mai 2025, 15:07 Uhr
Die Dokumentation für dieses Modul kann unter Modul:InterviewNavbox/Doku erstellt werden
local p = {}
local dateParser = require('Module:InterviewUtils')
-- Initialize caches
local dateRangeCache = {}
local parsedDateCache = {}
local function getDateRange(year)
-- Check if the year's range is cached
if not dateRangeCache[year] then
local ranges = {
{1980, 1995, 1},
{1996, 2005, 2},
{2006, 2015, 3},
{2016, 2020, 4},
{2021, 2025, 5},
{2026, 2030, 6},
}
for _, range in ipairs(ranges) do
if year >= range[1] and year <= range[2] then
dateRangeCache[year] = range[3] -- Cache the result
break
end
end
end
return dateRangeCache[year] or nil
end
function p.main(frame)
local dateRangeInput = tonumber(frame.args[1]) or 1
local content = mw.loadJsonData('DragonballWiki:Interviews')
local interviews_table = content.interviews
local list = {}
local titleGroup = {}
-- Group interviews by title without date
-- Use caching for date parsing
for _, interview in ipairs(interviews_table) do
local date = interview.date
-- Check if the parsed date is cached
if not parsedDateCache[date] then
parsedDateCache[date] = dateParser.parse(date) -- Cache the parsed date
end
local year = parsedDateCache[date]
local titleWithoutDate = string.match(interview.title, '^(.-)%s*%(.-%)$') or interview.title
titleGroup[titleWithoutDate] = titleGroup[titleWithoutDate] or {}
table.insert(titleGroup[titleWithoutDate], {interview = interview, year = year})
end
-- Generate list
for _, interview in ipairs(interviews_table) do
local year = dateParser.parse(interview.date)
local dateRange = getDateRange(year)
if dateRange == dateRangeInput then
local titleWithoutDate = string.match(interview.title, '^(.-)%s*%(.-%)$') or interview.title
local interviews = titleGroup[titleWithoutDate]
local hasMultipleInterviews = #interviews > 1
local itemTitle = hasMultipleInterviews and interview.title or titleWithoutDate
local item = frame:expandTemplate{title = 'INT', args = {interview.title, itemTitle}}
table.insert(list, '*' .. item)
end
end
return table.concat(list, '\n')
end
return p