Module:NamespaceTable: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Extract Shortdesc from page content | |||
local function getShortdesc(title) | |||
local t = mw.title.new(title) | |||
if not t or not t.exists then | |||
return "" | |||
end | |||
local content = t:getContent() | |||
if not content then | |||
return "" | |||
end | |||
-- Match {{Shortdesc|...}} | |||
local desc = content:match("{{%s*[Ss]hortdesc%s*|([^}]+)}}") | |||
if desc then | |||
return mw.text.trim(desc) | |||
end | |||
return "" | |||
end | |||
function p.table(frame) | function p.table(frame) | ||
| Line 7: | Line 29: | ||
local out = '{| class="wikitable"\n! Page !! Description\n' | local out = '{| class="wikitable"\n! Page !! Description\n' | ||
for _, | for _, title in ipairs(list) do | ||
title = mw.text.trim(title) | |||
if | if title ~= "" then | ||
local depth = select(2, title:gsub("/", "")) | local depth = select(2, title:gsub("/", "")) | ||
local indent = string.rep("— ", depth) | local indent = string.rep("— ", depth) | ||
local desc = getShortdesc(title) | |||
out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n' | out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n' | ||
end | end | ||
Latest revision as of 22:16, 10 April 2026
Documentation for this module may be created at Module:NamespaceTable/doc
local p = {}
-- Extract Shortdesc from page content
local function getShortdesc(title)
local t = mw.title.new(title)
if not t or not t.exists then
return ""
end
local content = t:getContent()
if not content then
return ""
end
-- Match {{Shortdesc|...}}
local desc = content:match("{{%s*[Ss]hortdesc%s*|([^}]+)}}")
if desc then
return mw.text.trim(desc)
end
return ""
end
function p.table(frame)
local pages = frame.args.pages or ""
local list = mw.text.split(pages, "\n")
local out = '{| class="wikitable"\n! Page !! Description\n'
for _, title in ipairs(list) do
title = mw.text.trim(title)
if title ~= "" then
local depth = select(2, title:gsub("/", ""))
local indent = string.rep("— ", depth)
local desc = getShortdesc(title)
out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n'
end
end
out = out .. '|}'
return out
end
return p