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 24: Line 24:


function h.DisplaySection(entry)
function h.DisplaySection(entry)
local diffYears = os.date("%Y") - tonumber(string.sub(entry["date"], 1, 4))
if not utilsCode.IsEmpty(entry) then
result = mw.html.create("div")
local diffYears = os.date("%Y") - tonumber(string.sub(entry["date"], 1, 4))
:addClass("infoblock")
result = mw.html.create("div")
:attr("id", "on-this-day")
:addClass("infoblock")
:node(mw.html.create("div")
:attr("id", "on-this-day")
:addClass("infoblock-header")
:node(mw.html.create("div")
:wikitext("On this day, " .. diffYears .. " years ago..."))
:addClass("infoblock-header")
:node(mw.html.create("div")
:wikitext("On this day, " .. diffYears .. " years ago..."))
:addClass("infoblock-content")
:node(mw.html.create("div")
:wikitext("[[File:" .. entry["filename"] .. "|150x150px|left]]" .. entry["text"]))
:addClass("infoblock-image")
:node(mw.html.create("div")
:wikitext("[[File:" .. entry["filename"] .. "|left|150x150px]]"))
:addClass("infoblock-read-more")
:node(mw.html.create("div")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki>")))
:addClass("infoblock-text")
:wikitext(entry["text"])
:node(mw.html.create("span")
:addClass("infoblock-read-more")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki>"))))
end
return result
return result
end
end


return p
return p

Revision as of 05:19, 10 February 2020

Lua error in package.lua at line 80: module 'Module:UtilsCode' not found.


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 formattedDate = "03-03"
	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)
	if not utilsCode.IsEmpty(entry) then
		local diffYears = os.date("%Y") - tonumber(string.sub(entry["date"], 1, 4))
		result = mw.html.create("div")
			:addClass("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-image")
				:wikitext("[[File:" .. entry["filename"] .. "|left|150x150px]]"))
			:node(mw.html.create("div")
				:addClass("infoblock-text")
				:wikitext(entry["text"])
				:node(mw.html.create("span")
					:addClass("infoblock-read-more")
					:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki>"))))
	end
	return result
end

return p