Module:On This Day: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
No edit summary
No edit summary
Line 36: Line 36:
end
end
local purgeButton = mw.html.create("span")
:addClass("plainlinks otd-refresh-button")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[{{FULLURL:Main Page|action=purge}} refresh]<nowiki>]</nowiki>"))
-- desktop version
local html = mw.html.create("div")
local desktopVersion = mw.html.create("div")
:addClass("infoblock")
:addClass("no-mobile infoblock")
:attr("id", "on-this-day")
:attr("id", "on-this-day")
:node(mw.html.create("div")
:tag("div")
:addClass("infoblock-header")
:addClass("infoblock-header")
:wikitext(header))
:wikitext(header)
:node(mw.html.create("div")
:done()
:addClass("infoblock-content")
:tag("div")
:wikitext("[[File:" .. entry["filename"] .. "|right|200x200px]]<span class='infoblock-title'>" .. entry["title"] .. "</span><br>" .. entry["text"]))
:node(mw.html.create("div")
:addClass("infoblock-read-more")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki><br><nowiki>[</nowiki>[{{FULLURL:Main Page|action=purge}} Click here to purge the cache]<nowiki>]</nowiki>")))
-- mobile version
local mobileVersion = mw.html.create("div")
:addClass("mobile-only infoblock")
:attr("id", "on-this-day")
:node(mw.html.create("div")
:addClass("infoblock-header")
:wikitext(header))
:node(mw.html.create("div")
:addClass("infoblock-title")
:addClass("infoblock-title")
:wikitext(entry["title"]))
:tag("div")
:node(mw.html.create("div")
:addClass("infoblock-title-text")
:wikitext(entry["title"])
:done()
:tag("span")
:addClass("plainlinks otd-refresh-button")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[{{FULLURL:Main Page|action=purge}} refresh]<nowiki>]</nowiki>"))
:done()
:done()
:tag("div")
:addClass("infoblock-content")
:addClass("infoblock-content")
:wikitext("[[File:" .. entry["filename"] .. "|right|150x150px]]" .. entry["text"]))
:wikitext(entry["text"])
:node(mw.html.create("div")
:done()
:addClass("infoblock-read-more")
:tag("div")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki><br><nowiki>[</nowiki>[{{FULLURL:Main Page|action=purge}} Click here to purge the cache]<nowiki>]</nowiki>")))
:addClass("infoblock-image")
:wikitext("[[File:" .. entry["filename"] .. "|200x200px]]")
result = tostring(desktopVersion) .. tostring(mobileVersion)
:done()
return result
:done()
 
return tostring(html)
end
end


return p
return p

Revision as of 19:40, 25 October 2022


local p = {}
local h = {}
local cargo = mw.ext.cargo
local utilsString = require("Module:UtilsString")

function p._Main(frame)
	local entry = h.GetEntryForToday()
	return h.DisplaySection(entry)
end

function h.GetEntryForToday()
	local formattedDate = os.date("%m-%d")
	local entries = cargo.query("OnThisDay", "date, title, filename, text, link", {})
	
	local todayEntries = {}
	for key, entry in ipairs(entries) do
		if string.sub(entry["date"], 6) == formattedDate then
			table.insert(todayEntries, entry)
		end
	end
	return todayEntries[1]
end

function h.DisplaySection(entry)
	local result = ""
	local header = "On this day"
	if not utilsString.isEmpty(entry) then
		header = header .. ", " ..  (os.date("%Y") - tonumber(string.sub(entry["date"], 1, 4))) .. " years ago..."
	else
		header = header .. "..."
		entry = {}
		entry["filename"] = "LA Mr. Write Artwork.png"
		entry["title"] = "Nothing happened"
		entry["text"] = "But you can change that! All it takes is one edit to make history. [[Special:RecentChanges|Zelda Wiki history]], that is.\n* [https://discordapp.com/invite/eJnnvYb Join our Discord]\n* [[Guidelines:Getting Started|Learn how to edit]]\n* [[:Category:Articles Needing Attention|Check out pages needing attention]]"
		entry["link"] = "Guidelines:Getting Started"
	end
	
	local purgeButton = mw.html.create("span")
		:addClass("plainlinks otd-refresh-button")
		:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[{{FULLURL:Main Page|action=purge}} refresh]<nowiki>]</nowiki>"))
	
	local html = mw.html.create("div")
		:addClass("infoblock")
		:attr("id", "on-this-day")
		:tag("div")
			:addClass("infoblock-header")
			:wikitext(header)
			:done()
		:tag("div")
			:addClass("infoblock-title")
			:tag("div")
				:addClass("infoblock-title-text")
				:wikitext(entry["title"])
				:done()
			:tag("span")
				:addClass("plainlinks otd-refresh-button")
				:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[{{FULLURL:Main Page|action=purge}} refresh]<nowiki>]</nowiki>"))
				:done()
			:done()
		:tag("div")
			:addClass("infoblock-content")
			:wikitext(entry["text"])
			:done()
		:tag("div")
			:addClass("infoblock-image")
			:wikitext("[[File:" .. entry["filename"] .. "|200x200px]]")
			:done()
		:done()

	return tostring(html)
end

return p