Difference between revisions of "Module:Item timeline by year"

From Team Fortress Wiki
Jump to: navigation, search
(test)
 
m
Line 1: Line 1:
 
local p = {}
 
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.generate(f)
 
function p.generate(f)
 +
    local startYear = 2007 -- Game release
 +
    local currentYear = tonumber(os.date("%Y"))
 +
 
     local output = {}
 
     local output = {}
    local startYear = 2007
 
    local currentYear = tonumber(os.date("%Y"))
 
    local split = f.args[1] or 6
 
 
     local if_lang = f:expandTemplate{title='If lang'}
 
     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
 
     for year = startYear, currentYear, split do
 
         table.insert(output, '<div style="display:inline-table">')
 
         table.insert(output, '<div style="display:inline-table">')
  
 
         for y = year, math.min(year + split - 1, currentYear) do
 
         for y = year, math.min(year + split - 1, currentYear) do
             table.insert(output, string.format(':*  [[Item timeline in %d%s|%d]]', y, if_lang, y))
+
             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
 
         end
  

Revision as of 19:57, 21 March 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.generate(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