Module:Live song counter: Difference between revisions
No edit summary |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local p = {} | local p = {} | ||
-- Helper function to remove "The" from the start of a title for sorting purposes | |||
local function sortTitle(title) | |||
if title:sub(1, 4) == "The " then | |||
return title:sub(5) -- Remove "The " from the start of the string | |||
end | |||
return title | |||
end | |||
function p.main(frame) | function p.main(frame) |
Revision as of 18:07, 7 April 2025
Documentation for this module may be created at Module:Live song counter/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Helper function to remove "The" from the start of a title for sorting purposes
local function sortTitle(title)
if title:sub(1, 4) == "The " then
return title:sub(5) -- Remove "The " from the start of the string
end
return title
end
function p.main(frame)
local args = getArgs(frame)
return p._main(args, frame)
end
function p._main(args, frame)
local output = '{| class="wikitable sortable"'
output = output .. '\n! Song !! Times performed !! Earliest known performance !! Latest known performance'
for i, song in ipairs(args) do
if song and song ~= "" then
local songLink = "\"[[" .. song .. "]]\""
-- Times performed
local timesPerformed = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|format=count}}')
-- Earliest known performance
local earliestDate = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert date=|sort=Concert date|order=asc|limit=1|link=none|searchlabel=|mainlabel=-}}')
local earliestCity = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert city=|sort=Concert date|order=asc|mainlabel=-|limit=1|searchlabel=}}')
local earliest = earliestDate .. ' in ' .. earliestCity
-- Latest known performance
local latestDate = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|sort=Concert date|order=desc|limit=1|format=inline|searchlabel=|template=Date format}}')
local latestCity = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert city=|sort=Concert date|order=desc|mainlabel=-|limit=1|searchlabel=}}')
local latest = latestDate .. ' in ' .. latestCity
output = output .. '\n|-\n| ' .. songLink
output = output .. ' || style="text-align:center;" | ' .. timesPerformed
output = output .. ' || ' .. earliest
output = output .. ' || ' .. latest
end
end
output = output .. '\n|}'
return output
end
return p