Module:InterviewNavbox

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 09:56, 6 May 2023 by Vish (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:InterviewNavbox/doc

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 = {}
    
    for _, interview in ipairs(interviews_table) do
        local year = dateParser.parse(interview.date)
        local dateRange = getDateRange(year)
        
        if dateRange == dateRangeInput then
            local item = frame:expandTemplate{title = 'INT', args = {interview.title}}
            table.insert(list, '*' .. item)
        end
    end
    
    return table.concat(list, '\n')
end

return p