Module:On This Day: Difference between revisions
Jump to navigation
Jump to search
MannedTooth (talk | contribs) No edit summary |
MannedTooth (talk | contribs) (empty days support) |
||
Line 24: | Line 24: | ||
function h.DisplaySection(entry) | function h.DisplaySection(entry) | ||
local result = "" | local result = "" | ||
local header = "On this day" | |||
if not utilsCode.IsEmpty(entry) then | if not utilsCode.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! [[Guidelines:Getting Started|Learn how you can contribute to Zelda Wiki]] and start making history!" | |||
entry["link"] = "Guidelines:Getting Started" | |||
end | |||
-- 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(header)) | |||
:node(mw.html.create("div") | |||
:addClass("infoblock-content") | |||
:wikitext("[[File:" .. entry["filename"] .. "|left|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>"))) | |||
-- 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") | |||
:wikitext(entry["title"])) | |||
:node(mw.html.create("div") | |||
:addClass("infoblock-content") | |||
:wikitext("[[File:" .. entry["filename"] .. "|left|150x150px]]" .. entry["text"])) | |||
:node(mw.html.create("div") | |||
:addClass("infoblock-read-more") | |||
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki>"))) | |||
result = tostring(desktopVersion) .. tostring(mobileVersion) | |||
return result | return result | ||
end | end | ||
return p | return p |
Revision as of 00:43, 11 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 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 utilsCode.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! [[Guidelines:Getting Started|Learn how you can contribute to Zelda Wiki]] and start making history!"
entry["link"] = "Guidelines:Getting Started"
end
-- 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(header))
:node(mw.html.create("div")
:addClass("infoblock-content")
:wikitext("[[File:" .. entry["filename"] .. "|left|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>")))
-- 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")
:wikitext(entry["title"]))
:node(mw.html.create("div")
:addClass("infoblock-content")
:wikitext("[[File:" .. entry["filename"] .. "|left|150x150px]]" .. entry["text"]))
:node(mw.html.create("div")
:addClass("infoblock-read-more")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki>")))
result = tostring(desktopVersion) .. tostring(mobileVersion)
return result
end
return p