Module:NamespaceTable: Difference between revisions
Appearance
Created page with "local p = {} 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 t = mw.title.new(title) local desc = "" if t and t.exists then -- Get SHORTDESC via page properties local prop..." |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| 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 11: | Line 33: | ||
if title ~= "" then | if title ~= "" then | ||
local | local depth = select(2, title:gsub("/", "")) | ||
local | local indent = string.rep("— ", depth) | ||
local desc = getShortdesc(title) | |||
out = out .. '|-\n| [[' .. title .. ']] || ' .. desc .. '\n' | out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n' | ||
end | end | ||
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