Module:InterviewNavbox

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

local function getDateRange(year) if year >= 1981 and year <= 1995 then return 1 elseif year >= 1996 and year <= 2005 then return 2 elseif year >= 2006 and year <= 2015 then return 3 elseif year >= 2016 and year <= 2020 then return 4 elseif year >= 2021 and year <= 2025 then return 5 elseif year >= 2026 and year <= 2030 then return 6 end return nil end

function p.main(frame) local dateRangeInput = tonumber(frame.args[1]) or 1 local content = mw.loadJsonData('JoJo Wiki:Interviews') local interviews_table = content.interviews local list = {} local titleGroup = {}

-- Group interviews by title without date for _, interview in ipairs(interviews_table) do       local year = dateParser.parse(interview.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