Module:InterviewArchive

local utils = require('Module:InterviewUtils') local p = {}

local function cleanIntervieweeName(interviewee) local cleaned = mw.text.trim(interviewee) cleaned = string.gsub(cleaned, '%[%[(.-)%]%]', '%1') -- remove wikitext link cleaned = string.gsub(cleaned, '', '%2') -- handle template with piped link cleaned = string.gsub(cleaned, '', '%1') -- remove template cleaned = string.gsub(cleaned, '%[extlink (.-)%]', '%1') -- remove external link cleaned = string.gsub(cleaned, "'", '&#39;') -- replace single quotes with HTML character entity return cleaned end

local function generateInterview(interview, frame) local output = {} local year = utils.parse(interview.date) local year, _, _ = utils.parse(interview.date) -- get the year from the date

local cleanInterviewees = {} for _, interviewee in ipairs(interview.interviewee) do	   local cleanInterviewee = cleanIntervieweeName(interviewee) table.insert(cleanInterviewees, cleanInterviewee) end local function valueOrDefault(value, default) if value == nil or value == '' then return default else return value end end

table.insert(output, '') table.insert(output, ' ') if interview.cover ~= '' then table.insert(output, '') else table.insert(output, '') end table.insert(output, ' ') table.insert(output, ' ') table.insert(output, ' ') table.insert(output, '') table.insert(output, ' ') table.insert(output, ' ') if interview.display then table.insert(output, frame:preprocess("")) else table.insert(output, frame:preprocess("")) end table.insert(output, ' ') table.insert(output, ' ') if interview.translation then table.insert(output, frame:preprocess('<' .. interview.translation .. ' >'))   end if interview.transcript then table.insert(output, frame:preprocess('<' .. interview.transcript .. '2 >'))   end table.insert(output, frame:preprocess('<' .. interview.media .. ' >'))   table.insert(output, frame:preprocess('<' .. interview.type .. ' >'))   table.insert(output, frame:preprocess('right')) table.insert(output, ' 👤 ') for i, person in ipairs(interview.interviewee) do	 if i > 1 then table.insert(output, ", ") end table.insert(output, frame:preprocess(person)) end

table.insert(output, ' ') table.insert(output, ' 📜 ') for _, tag in ipairs(interview.tags) do       table.insert(output, frame:preprocess('<' .. tag .. ' >'))   end table.insert(output, '    ') 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('JoJo Wiki:Interviews').interviews

-- Find the interview with the matching title local interview = nil for i, v in ipairs(interviewsJson) do       if v.title == interviewTitle then interview = v           break end end

-- If we found the interview, generate it   if interview ~= nil then return generateInterview(interview, frame) else return "Interview not found" end end

function p.generateArchive(frame) local content = mw.loadJsonData('JoJo Wiki:Interviews').interviews local html = {' '} -- Start the div with the ID 'interview-container' for _, interview in ipairs(content) do       table.insert(html, generateInterview(interview, frame)) end

table.insert(html, ' ') -- 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, "'", '&#39;')

-- Load the interviews from JSON data local content = mw.loadJsonData('JoJo Wiki: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" |#|| class="unsortable" |Interview||Type||Media||Published') for i, interview in ipairs(interviewsForPerson) do	       local title = interview.display if title == nil then title = interview.title end table.insert(output, '|-') table.insert(output, '|' .. i .. '|| style="color:white; background: ; text-shadow: 1px 1px 1px #333333;"|||<' .. interview.type .. ' >||<' .. interview.media .. ' >||' .. interview.date) end table.insert(output, '|}') return frame:preprocess(table.concat(output, '\n')) else return "No interviews found for " .. targetInterviewee end end

return p