Module:InterviewNavbox

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 09:46, 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 function getDateRange(dateString)
    local year = tonumber(dateString:sub(1, 4))
    
    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 dateRange = getDateRange(interview.date)
        
        if dateRange == dateRangeInput then
            table.insert(list, '*{{INT|' .. interview.title .. '}}')
        end
    end
    
    return table.concat(list, '\n')
end

return p