Module:InterviewNavbox: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
local dateParser = require('Module:InterviewUtils') |
local dateParser = require('Module:InterviewUtils') |
||
-- Initialize caches |
|||
local dateRangeCache = {} |
|||
local parsedDateCache = {} |
|||
local function getDateRange(year) |
local function getDateRange(year) |
||
-- Check if the year's range is cached |
|||
local ranges = { |
|||
if not dateRangeCache[year] then |
|||
⚫ | |||
local ranges = { |
|||
{ |
{1981, 1995, 1}, |
||
{ |
{1996, 2005, 2}, |
||
{ |
{2006, 2015, 3}, |
||
{ |
{2016, 2020, 4}, |
||
⚫ | |||
⚫ | |||
{2026, 2030, 6}, |
|||
⚫ | |||
⚫ | |||
⚫ | |||
for _, range in ipairs(ranges) do |
|||
⚫ | |||
dateRangeCache[year] = range[3] -- Cache the result |
|||
break |
|||
end |
|||
end |
end |
||
end |
end |
||
return nil |
return dateRangeCache[year] or nil |
||
end |
end |
||
Line 27: | Line 35: | ||
-- Group interviews by title without date |
-- Group interviews by title without date |
||
-- Use caching for date parsing |
|||
for _, interview in ipairs(interviews_table) do |
|||
⚫ | |||
local year = dateParser.parse(interview.date) |
|||
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 |
end |
||
local year = parsedDateCache[date] |
|||
local titleWithoutDate = string.match(interview.title, '^(.-)%s*%(.-%)$') or interview.title |
|||
⚫ | |||
⚫ | |||
end |
|||
-- Generate list |
-- Generate list |
Latest revision as of 06:42, 28 February 2024
Documentation for this module may be created at Module:InterviewNavbox/doc
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 = {
{1981, 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('JoJo Wiki: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