Module:About
Documentation for this module may be created at Module:About/doc
local p = {}
-- List of phrases that should bypass the default logic
local custom_starts = {
"For", "Main", "Not", "Related", "This"
}
local function starts_with_any(text, patterns)
for _, pat in ipairs(patterns) do
if mw.ustring.sub(text, 1, #pat) == pat then
return true
end
end
return false
end
function p.about(frame)
local arg1 = frame.args[1] or ""
local arg2 = frame.args[2] or ""
local arg3 = frame.args[3] or ""
local title = mw.title.getCurrentTitle().text
-- Try to get the part before ":" in the title
local colon_pos = mw.ustring.find(title, ":")
local title_before_colon = colon_pos and mw.ustring.sub(title, 1, colon_pos - 1) or title
-- If arg1 starts with a special phrase, output it as-is
if starts_with_any(arg1, custom_starts) then
return string.format(
'<div style="padding-left:1.6em;margin-bottom:0.5em;font-style:italic">%s</div>[[Category:About/Unique Text]]',
arg1
)
end
-- Otherwise, build the standard hatnote
local about_text = "This article is about "
if arg1 ~= "" then
if colon_pos then
about_text = about_text .. arg1 .. " of '''" .. title_before_colon .. "'''"
else
about_text = about_text .. arg1
end
end
local other_versions = (arg2 ~= "" and arg2) or "other versions"
local see_target = (arg3 ~= "" and ("[[" .. arg3 .. "]]")) or ("[[" .. title_before_colon .. "]]")
local result = string.format(
'<div style="padding-left:1.6em;margin-bottom:0.5em;font-style:italic">%s. For %s, see %s.</div>[[Category:About/Unique Text]]',
about_text, other_versions, see_target
)
return result
end
return p