Module:Catégorie par date

De Wicri Animaux
Révision datée du 26 mars 2025 à 23:21 par imported>Jacques Ducloy (Page créée avec « local p = {} function p.categorize(frame) local args1 = frame:getParent().args local args2 = frame.args local dateparam = args1[1] if (not dateparam) or dateparam =... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)

La documentation pour ce module peut être créée à Module:Catégorie par date/doc

local p = {}

function p.categorize(frame)
	local args1 = frame:getParent().args
	local args2 = frame.args
	
	local dateparam = args1[1]
	if (not dateparam) or dateparam == '' then return nil end
	
	local prefix = args2.prefix
	local suffix = args2.suffix
	if prefix then prefix = prefix .. ' ' else prefix = '' end
	if suffix then suffix = ' ' .. suffix else suffix = '' end
	local default = args2.default or 'Échec de Module:Catégorie par date'
	local datemin = tonumber(args2.datemin) or 2024
	local datemax = tonumber(args2.datemax) or 2024
	
	local catstring
	for datenum = datemin,datemax do
		local datestring = tostring(datenum)
		if mw.ustring.find(dateparam,datestring) then
			catstring = '[[Category:' .. prefix .. datestring .. suffix .. ']]'
			return catstring
		end
	end
	
	catstring = '[[Category:' .. default .. ']]'
	return catstring
end
 
return p