Module:Year in sports
Appearance
![]() | This module depends on the following other modules: |
Implements {{Year in sports}}.
local getArgs = require('Module:Arguments').getArgs
local sidebar = require('Module:Sidebar')
local list = require('Module:List')
local parser = mw.ext.ParserFunctions
local sports = {
"American Football",
"aquatic sports",
"association football",
"badminton",
"baseball",
"basketball",
"chess",
"climbing",
"combat sports",
"sumo",
"cycling",
"equestrianism",
"esports",
"golf",
"gymnastics",
"ice sports",
"modern pentathlon",
"motorsport",
"racquetball",
"sailing",
"skiing",
"squash",
"table tennis",
"tennis",
"triathlon",
"volleyball",
"weightlifting"
}
local p = {}
function p.main(frame)
local args = getArgs(frame)
return p._main(frame, args)
end
function p._main(frame, args)
local year = args[1] or args['year'] or os.date("%Y")
local pages = {}
for i, sport in ipairs(sports) do
local s = year .. " in " .. sport
local page = mw.title.new(s, 0)
if (page.exists) then
table.insert(pages, "[[" .. s .. "|" .. sport:gsub("^%l", string.upper) .. "]]")
end
end
local l = list.horizontal(pages)
local below = year
if (mw.title.new((year - 1) .. " in sports")) then
below = "[[" .. (year - 1) .. " in sports|" .. (year - 1) .. "]]" .. below
end
if (mw.title.new((year - 2) .. " in sports")) then
below = "[[" .. (year - 2) .. " in sports|" .. (year - 2) .. "]]" .. below
end
if (mw.title.new((year - 3) .. " in sports")) then
below = "[[" .. (year - 3) .. " in sports|" .. (year - 3) .. "]]" .. below
end
if (mw.title.new((year - 4) .. " in sports")) then
below = "[[" .. (year - 4) .. " in sports|" .. (year - 4) .. "]]" .. below
end
if (mw.title.new((year + 1) .. " in sports")) then
below = below .. "[[" .. (year + 1) .. " in sports|" .. (year + 1) .. "]]"
end
if (mw.title.new((year + 2) .. " in sports")) then
below = below .. "[[" .. (year + 2) .. " in sports|" .. (year + 2) .. "]]"
end
if (mw.title.new((year + 3) .. " in sports")) then
below = below .. "[[" .. (year + 3) .. " in sports|" .. (year + 3) .. "]]"
end
if (mw.title.new((year + 4) .. " in sports")) then
below = below .. "[[" .. (year + 4) .. " in sports|" .. (year + 4) .. "]]"
end
local passing = {
name = "Year in sports",
title = "[[" .. year .. " in sports]]",
content1 = l,
below = below
}
local currentTitle = mw.title.getCurrentTitle()
return sidebar.sidebar(frame, passing)
end
return p