Module:On This Day

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. Zelda Wiki history, that is.\n* Join our Discord\n* Learn how to edit\n* 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(" [ [ refresh] ] ")) 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-body") :tag("div") :addClass("infoblock-text") :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(" [ [ refresh] ] ")) :done :done :tag("div") :addClass("infoblock-content") :wikitext(entry["text"]) :done :done :tag("div") :addClass("infoblock-image") :wikitext("") :done :done

return tostring(html) end

return p