Module:Category described in year: Difference between revisions

Content deleted Content added
m -something
Mini working example for Fish cats
Line 1:
require('Module:No globals')
 
local map = {
['Fish'] = { --group
['year'] = { --smallest branch, [[Category:Fish described in 1901]]
['parent1'] = 'century', --'year', 'decade', 'century'
['parent2'] = 'Animals', --[[Category:Animals described in the 20th century]]
},
['century'] = { --parent branch, [[Category:Fish described in the 20th century]]
['parent1'] = 'formal', --[[Category:Fish by year of formal description]]
['parent2'] = 'Animals', --[[Category:Animals described in the 20th century]]
},
},
}
 
local p = {}
Line 10 ⟶ 23:
if currentTitle.namespace == 14 then --Category:
--determine current cat's properties
local catcurrCat = currentTitle.text --without namespace nor interwiki prefixes
local group = mw.ustring.match(cat, '^%w+')
local yearcurrGroup = mw.ustring.match(catcurrCat, '^%d%d%d%d$w+') --Fish/Spiders/etc.
local centurycurrYDC = '' --placeholder for year/decade/century
local groupcurrYear = mw.ustring.match(catcurrCat, '^%w+d%d%d%d$')
local currCent = mw.ustring.match(currCat, 'the (%d+)[snrt][tdh] century')
if currYear then currYDC = 'year' end
if currCent then currYDC = 'century' end
local parentCent = ''
local ord = ''
if yearcurrYear then centuryparentCent = 1 + mw.ustring.match(yearcurrYear, '^%d%d') end
if centuryparentCent then
local lastd = mw.ustring.match(centuryparentCent, '%d$')
if lastd == 1 then ord = 'st'
elseif lastd == 2 then ord = 'nd'
Line 23 ⟶ 42:
else ord = 'th' end
end
if group and group == 'Fish' then
local iparent = 1
categories[1] = '[[Fish described in the ' .. century .. ord .. ' century]]' ..
local parenti = 'parent' .. iparent
'[[Animals described in ' .. year .. ']]'
while currYDC and map[currGroup][currYDC][parenti] do
if group and groupcurrYDC == 'Fishyear' then
if map[currGroup][currYDC][parenti] == 'century' then
categories[iparent] = '[[:Category:' .. currGroup .. ' described in the ' .. parentCent .. ord .. ' century]]'
end
if map[currGroup][currYDC][parenti] == 'Animals' then
categories[iparent] = '[[:Category:Animals described in ' .. yearcurrYear .. ']]'
end
elseif currYDC == 'decade' then
elseif currYDC == 'century' then
if map[currGroup][currYDC][parenti] == 'formal' then
categories[iparent] = '[[:Category:' .. currGroup .. ' by year of formal description|' .. currCent .. ord .. ']]'
end
if map[currGroup][currYDC][parenti] == 'Animals' then
categories[1iparent] = '[[Fish:Category:Animals described in the ' .. centurycurrCent .. ord .. ' century]]' ..
end
end
iparent = iparent + 1
parenti = 'parent' .. iparent
end
elseif currentTitle.namespace == 10 then --Module:/Template: sandbox/testcases/doc
end
outString = header .. outString
if string.sub(currentTitle.subpageText,1,9) == 'testcases' then
outString = outString .. mw.text.nowiki(table.concat(categories)) .. '<br />'
elseif currentTitle.namespace == 14 then --Category:
outString = header .. outString .. table.concat(categories)
else
outString = ''