Jump to content

Module:Events by year for decade

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by GKFX (talk | contribs) at 21:45, 5 May 2021 (Convert Template:Events_by_year_for_decade to Lua). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

p.main = function(frame)
	frame.args = frame:getParent().args
	return p[''](frame)
end

p[''] = function(frame)
	local output = {
		frame:expandTemplate{ title = 'TOC limit', args = {3} },
		'\n==Events==\n'
	}
	local n = tonumber((frame.args[1] or '0') .. '0') or 0
	
	for i = n, n + 9 do
		if i == 0 then output[3] = '' else
			local year =  frame:expandTemplate{ title='dr', args={'y', 'y', i, 0, n < 100 and 'na' or 'n'}}
			local year2 = frame:expandTemplate{ title='dr', args={'y', 'y', i, 0, n < 1000 and 'na' or 'n'}}
			local section = '== ' .. year .. '==\n' .. mw.text.trim(
				frame:expandTemplate{ title ='transcluded section', args = { year2 }} .. ' ' ..
				frame:callParserFunction( '#section-h', {':' .. year2, 'Events'}))
			output[1 + #output] = section:gsub('==', '===') .. '\n'
		end
	end

	output[13] = '[[Category:' .. n ..'s]]'
	return table.concat(output)
end

return p