Module:Category described in year: Difference between revisions

Content deleted Content added
+|min= navbar functionality
m Style tweaks
Line 37:
 
local function addOrd( i ) --20 -> 20th, etc.
if i and tonumber(i) then
local s = tostring(i)
local lastd = mw.ustring.match(s, '%d$')
if lastd == '1' then return s .. 'st'
elseif lastd == '2' then return s .. 'nd'
elseif lastd == '3' then return s .. 'rd'
elseif lastd ~= nil then return s .. 'th'
else return '' end
else
Line 54:
function p.autodetect( frame )
local currentTitle = mw.title.getCurrentTitle()
local header = ' ' --header template(s), nav bar, and category description text; whitespace-initialized for convenience
local nav = nil
local description = nil
local header = ' ' --header template(s), nav bar, and category description text
local categories = {}
local outString = nil
Line 68:
local currDeca = mw.ustring.match(currCat, 'the (%d%d%d%d)s$')
local currCent = mw.ustring.match(currCat, 'the (%d+)[snrt][tdh] century')
local parentCent = nil --used with currYear (i.e. Fish) & currDeca (i.e. Spiders)
local parentDeca = nil --used with currYear (i.e. Spiders) & currDeca (i.e. Spiders)
local parentCent = nil --used with currYear (i.e. Fish) & currDeca (i.e. Spiders)
local lastCent, nextCent = nil, nil --used with currYear (i.e. Fish) & currCent (i.e. Fish)
local minYear = tonumber(map[currGroup].min)
Line 94:
return '' --add err msg/cat?
end
description = map[currGroup][currYDC].description
--produce cats & navs
local iparent = 1
local parenti = 'parent' .. iparent
while currYDC and map[currGroup][currYDC][parenti] do
local parent = map[currGroup][currYDC][parenti]
if description == nil then
description = map[currGroup][currYDC].description
end
if currYDC == 'year' then
Line 117 ⟶ 114:
categories[iparent] = '[[:Category:' .. parent .. ' described in ' .. currYear .. ']]'
end
elseif currYDC == 'decade' then
if nav == nil then
nav = frame:expandTemplate{ title = 'Container category' }
local args = { decade = currDeca, min = minYear, cat = currGroup .. ' described in the' }
nav = frame:expandTemplate{ title = 'Category by decade', args = args }
Line 127 ⟶ 126:
categories[iparent] = '[[:Category:' .. parent .. ' described in the ' .. currDeca .. 's]]'
end
end
elseif currYDC == 'century' then
if nav == nil then