Module:On This Day

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

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 = "" if not utilsCode.IsEmpty(entry) then local diffYears = os.date("%Y") - tonumber(string.sub(entry["date"], 1, 4)) -- desktop version local desktopVersion = mw.html.create("div") :addClass("no-mobile infoblock") :attr("id", "on-this-day") :node(mw.html.create("div")				:addClass("infoblock-header")				:wikitext("On this day, " .. diffYears .. " years ago...")) :node(mw.html.create("div")				:addClass("infoblock-content")				:wikitext(" " .. entry["title"] .. " " .. entry["text"])) :node(mw.html.create("div")				:addClass("infoblock-read-more")				:wikitext(mw.getCurrentFrame:preprocess(" [ Read more... ] "))) -- 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("On this day, " .. diffYears .. " years ago...")) :node(mw.html.create("div")				:addClass("infoblock-title")				:wikitext(entry["title"])) :node(mw.html.create("div")				:addClass("infoblock-content")				:wikitext("" .. entry["text"])) :node(mw.html.create("div")				:addClass("infoblock-read-more")				:wikitext(mw.getCurrentFrame:preprocess(" [ Read more... ] "))) result = tostring(desktopVersion) .. tostring(mobileVersion) end return result end

return p