Module:UpdateExcerpt: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Undo revision 62037 by Monster Domosed (talk) Tag: Undo |
No edit summary |
||
| (23 intermediate revisions by 4 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function | local function _render(month, day, year, maxLines, frame) | ||
if not month or month == "" or not day or day == "" or not year or year == "" then | |||
return '<span class="error">Usage Error: Missing date components (Month, Day, or Year).</span>' | |||
if not month or not day or not year then | |||
return '<span class="error">Usage: | |||
end | end | ||
local pageTitle = "Update:" .. month .. " " .. day .. ", " .. year | local pageTitle = "Update:" .. month .. " " .. day .. ", " .. year | ||
| Line 30: | Line 18: | ||
end | end | ||
local notesRaw = content:match("|%s*notes%s*=(.*)") | |||
if not notesRaw then | |||
local | |||
if not | |||
return '<span class="error">No notes parameter found on [[' .. pageTitle .. ']]</span>' | return '<span class="error">No notes parameter found on [[' .. pageTitle .. ']]</span>' | ||
end | end | ||
notesRaw = notesRaw:gsub("%s*}}%s*$", "") | |||
notesRaw = mw.text.trim(notesRaw) | notesRaw = mw.text.trim(notesRaw) | ||
| Line 57: | Line 30: | ||
end | end | ||
------ | local maxHeight = maxLines * 1.7 | ||
local html = string.format( | |||
local | '<div style="flex:1; min-height:0; overflow-y:auto; padding:14px 18px; font-family: sans-serif; font-size:0.92em; line-height:1.7;">\n__NOEDITSECTION__\n%s\n</div>', | ||
frame:preprocess(notesRaw) | |||
) | |||
return html | |||
end | end | ||
function p.getDateLink(frame) | |||
local parentArgs = frame:getParent().args or {} | |||
local args = frame.args or {} | |||
local month = parentArgs.month or args.month or parentArgs[1] or args[1] or "" | |||
local day = parentArgs.day or args.day or parentArgs[2] or args[2] or "" | |||
local year = parentArgs.year or args.year or parentArgs[3] or args[3] or "" | |||
month = mw.text.trim(month) | |||
day = mw.text.trim(day) | |||
year = mw.text.trim(year) | |||
if month == "" or day == "" or year == "" then | |||
local latestUpdate = require("Module:LatestUpdate") | |||
if month == "" then month = latestUpdate.month() end | |||
if day == "" then day = latestUpdate.day() end | |||
if year == "" then year = latestUpdate.year() end | |||
end | end | ||
if | return "[[Update:" .. month .. " " .. day .. ", " .. year .. "| ".. month .. " " .. day .. ", " .. year .. "]]" | ||
end | |||
end | |||
function p.render(frame) | |||
local args = frame.args | |||
if not args[1] then args = frame:getParent().args end | |||
local month = args[1] | |||
local day = args[2] | |||
local year = args[3] | |||
local maxLines = tonumber(args[4]) or 10 | |||
return _render(month, day, year, maxLines, frame) | |||
end | |||
function p.drawWidget(frame) | |||
local parentArgs = frame:getParent().args | |||
local args = frame.args | |||
local month = parentArgs.month or args.month or "" | |||
local day = parentArgs.day or args.day or "" | |||
local year = parentArgs.year or args.year or "" | |||
local height = tonumber(parentArgs.height or args.height) or 15 | |||
local lang = parentArgs.lang or args.lang or "" | |||
month = mw.text.trim(month) | |||
day = mw.text.trim(day) | |||
year = mw.text.trim(year) | |||
-- Native Lua loading: Bypasses frame:preprocess entirely | |||
local latestUpdate = require("Module:LatestUpdate") | |||
if month == "" then month = latestUpdate.month() end | |||
if day == "" then day = latestUpdate.day() end | |||
if year == "" then year = latestUpdate.year() end | |||
-- Execute days_since_text natively by passing a mock frame table | |||
local daysSinceText = latestUpdate.days_since_text({ args = { lang = lang } }) | |||
-- Standard template expansions for structural layout | |||
local translateText = frame:expandTemplate{ title = "Translate", args = { "Latest Update" } } | |||
local updateLink = frame:expandTemplate{ title = "Update link", args = { month, day, year } } | |||
-- Fetch the inner excerpt HTML | |||
local excerptBody = _render(month, day, year, height, frame) | |||
-- Build optimized wrapper HTML layout | |||
local html = mw.html.create("div") | |||
:addClass("nav-bg update-excerpt") | |||
-- | -- Header Segment | ||
html:tag("div") | |||
:addClass("update-excerpt__header") | |||
:wikitext(translateText .. ": " .. updateLink .. " (" .. daysSinceText .. ")") | |||
-- Append Excerpt Body Content | |||
html:wikitext(excerptBody) | |||
-- Footer Segment | |||
local footer = html:tag("div") | |||
:addClass("update-excerpt__footer nav-bg") | |||
footer:tag("span") | |||
:addClass("update-excerpt__readmore") | |||
:wikitext("[[Update:" .. month .. " " .. day .. ", " .. year .. "|Read more]]") | |||
return | return tostring(html) | ||
end | end | ||
return p | return p | ||
Latest revision as of 20:53, 25 August 2026
Documentation for this module may be created at Module:UpdateExcerpt/doc
local p = {}
local function _render(month, day, year, maxLines, frame)
if not month or month == "" or not day or day == "" or not year or year == "" then
return '<span class="error">Usage Error: Missing date components (Month, Day, or Year).</span>'
end
local pageTitle = "Update:" .. month .. " " .. day .. ", " .. year
local titleObj = mw.title.new(pageTitle)
if not titleObj then
return '<span class="error">Invalid page title: ' .. pageTitle .. '</span>'
end
local content = titleObj:getContent()
if not content then
return '<span class="error">Page not found: [[' .. pageTitle .. ']]</span>'
end
local notesRaw = content:match("|%s*notes%s*=(.*)")
if not notesRaw then
return '<span class="error">No notes parameter found on [[' .. pageTitle .. ']]</span>'
end
notesRaw = notesRaw:gsub("%s*}}%s*$", "")
notesRaw = mw.text.trim(notesRaw)
if notesRaw == "" then
return ""
end
local maxHeight = maxLines * 1.7
local html = string.format(
'<div style="flex:1; min-height:0; overflow-y:auto; padding:14px 18px; font-family: sans-serif; font-size:0.92em; line-height:1.7;">\n__NOEDITSECTION__\n%s\n</div>',
frame:preprocess(notesRaw)
)
return html
end
function p.getDateLink(frame)
local parentArgs = frame:getParent().args or {}
local args = frame.args or {}
local month = parentArgs.month or args.month or parentArgs[1] or args[1] or ""
local day = parentArgs.day or args.day or parentArgs[2] or args[2] or ""
local year = parentArgs.year or args.year or parentArgs[3] or args[3] or ""
month = mw.text.trim(month)
day = mw.text.trim(day)
year = mw.text.trim(year)
if month == "" or day == "" or year == "" then
local latestUpdate = require("Module:LatestUpdate")
if month == "" then month = latestUpdate.month() end
if day == "" then day = latestUpdate.day() end
if year == "" then year = latestUpdate.year() end
end
return "[[Update:" .. month .. " " .. day .. ", " .. year .. "| ".. month .. " " .. day .. ", " .. year .. "]]"
end
function p.render(frame)
local args = frame.args
if not args[1] then args = frame:getParent().args end
local month = args[1]
local day = args[2]
local year = args[3]
local maxLines = tonumber(args[4]) or 10
return _render(month, day, year, maxLines, frame)
end
function p.drawWidget(frame)
local parentArgs = frame:getParent().args
local args = frame.args
local month = parentArgs.month or args.month or ""
local day = parentArgs.day or args.day or ""
local year = parentArgs.year or args.year or ""
local height = tonumber(parentArgs.height or args.height) or 15
local lang = parentArgs.lang or args.lang or ""
month = mw.text.trim(month)
day = mw.text.trim(day)
year = mw.text.trim(year)
-- Native Lua loading: Bypasses frame:preprocess entirely
local latestUpdate = require("Module:LatestUpdate")
if month == "" then month = latestUpdate.month() end
if day == "" then day = latestUpdate.day() end
if year == "" then year = latestUpdate.year() end
-- Execute days_since_text natively by passing a mock frame table
local daysSinceText = latestUpdate.days_since_text({ args = { lang = lang } })
-- Standard template expansions for structural layout
local translateText = frame:expandTemplate{ title = "Translate", args = { "Latest Update" } }
local updateLink = frame:expandTemplate{ title = "Update link", args = { month, day, year } }
-- Fetch the inner excerpt HTML
local excerptBody = _render(month, day, year, height, frame)
-- Build optimized wrapper HTML layout
local html = mw.html.create("div")
:addClass("nav-bg update-excerpt")
-- Header Segment
html:tag("div")
:addClass("update-excerpt__header")
:wikitext(translateText .. ": " .. updateLink .. " (" .. daysSinceText .. ")")
-- Append Excerpt Body Content
html:wikitext(excerptBody)
-- Footer Segment
local footer = html:tag("div")
:addClass("update-excerpt__footer nav-bg")
footer:tag("span")
:addClass("update-excerpt__readmore")
:wikitext("[[Update:" .. month .. " " .. day .. ", " .. year .. "|Read more]]")
return tostring(html)
end
return p