Jump to content

Module:TFA title

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Legoktm (talk | contribs) at 00:42, 29 December 2022 (Make is_todays_tfa usable with {{#if}}). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local data = mw.loadJsonData("Template:TFA title/data.json")

-- Get the TFA title for the specified "YYYY-MM-DD" date. May be
-- a single title, an array of multiple titles, or nil, if no title is known
function p.title(date)
	return data.titles[date] or nil
end

-- Today's TFA, see title() for possible return values
function p.today_title()
	return p.title(today())
end

-- Is the specified title today's TFA, returns "yes" or ""
-- so it can be used with {{#if:}}
function p.is_todays_tfa(title)
	local today = p.today_title()
	if today == nil then
		-- no clue
		return ""
	end
	if type(today) == "string" then
		if title == today then
			return "yes"
		else
			return ""
		end
	end
	
	-- table case, multiple titles
	for _, check in pairs( today ) do
		if check == title then
			return "yes"
		end
	end
	return ""
end

-- Internal, today's date as YYYY-MM-DD
function today()
	return os.date("%Y-%m-%d")
end


return p