Difference between revisions of "Module:Item timeline by year"
m |
m |
||
(2 intermediate revisions by the same user not shown) | |||
Line 13: | Line 13: | ||
-- Function to generate a fancy list :3 | -- Function to generate a fancy list :3 | ||
− | function p. | + | function p.list(f) |
local startYear = 2007 -- Game release | local startYear = 2007 -- Game release | ||
local currentYear = tonumber(os.date("%Y")) | local currentYear = tonumber(os.date("%Y")) | ||
Line 31: | Line 31: | ||
if article_exists(title) then | if article_exists(title) then | ||
− | table.insert(output, string.format(' | + | table.insert(output, string.format('* [[%s%s|%d]]', title, if_lang, y)) |
end | end | ||
end | end |
Latest revision as of 16:54, 24 April 2024
Usage
{{#invoke:Item timeline by year|list}}
produces:
{{#invoke:Item timeline by year|list|12}}
produces:
{{#invoke:Item timeline by year|list|1}}
produces:
{{#invoke:Item timeline by year|list|9999}}
produces:
local p = {} -- Function to check if an article exists function article_exists(article) local exists = mw.title.new(article) if exists and exists.exists then return true else return false end end -- Function to generate a fancy list :3 function p.list(f) local startYear = 2007 -- Game release local currentYear = tonumber(os.date("%Y")) local output = {} local if_lang = f:expandTemplate{title='If lang'} -- Determine the number of years grouped together in each "section" of the timeline -- Defaults to 6 because I like it local split = tonumber(f.args[1]) or 6 for year = startYear, currentYear, split do table.insert(output, '<div style="display:inline-table">') for y = year, math.min(year + split - 1, currentYear) do local title = string.format("Item timeline in %d", y) if article_exists(title) then table.insert(output, string.format('* [[%s%s|%d]]', title, if_lang, y)) end end table.insert(output, '</div>') end return table.concat(output, "\n") end return p