Module:Cat year: Difference between revisions
MusikAnimal (talk | contribs) No edit summary |
MusikAnimal (talk | contribs) m (Protected "Module:Cat year" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite))) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
-- Categorize each release | -- Categorize each release | ||
if cat_type | if cat_type == '' then | ||
cat_type = 'song' | |||
end | |||
for year in matches do | |||
date_str = date_str .. '[[Category:' .. year .. ' ' .. string.lower(cat_type) .. 's]]' | |||
end | end | ||
-- Categorize the first release as just 'song' or 'album', etc. | -- Categorize the first release as just 'song' or 'album', etc. | ||
local first_year = string.match( date_str, "%d%d%d%d" ) | local first_year = string.match( date_str, "%d%d%d%d" ) | ||
if first_year then | if first_year and cat_type ~= 'song' then | ||
date_str = date_str .. '[[Category:' .. first_year .. ' ' .. 'songs]]' | date_str = date_str .. '[[Category:' .. first_year .. ' ' .. 'songs]]' | ||
end | end |
Latest revision as of 22:04, 29 March 2023
Documentation for this module may be created at Module:Cat year/doc
local p = {}
function p.parse( frame )
local date_str = frame.args[1]
if date_str == '' then
return date_str
end
local cat_type = frame.args[2]
local matches = string.gmatch( date_str, "%d%d%d%d" )
-- Categorize each release
if cat_type == '' then
cat_type = 'song'
end
for year in matches do
date_str = date_str .. '[[Category:' .. year .. ' ' .. string.lower(cat_type) .. 's]]'
end
-- Categorize the first release as just 'song' or 'album', etc.
local first_year = string.match( date_str, "%d%d%d%d" )
if first_year and cat_type ~= 'song' then
date_str = date_str .. '[[Category:' .. first_year .. ' ' .. 'songs]]'
end
return date_str
end
return p