Jump to content

Module:NamespaceTable: Difference between revisions

From Costa Sano KB
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
Line 7: Line 7:
     local out = '{| class="wikitable"\n! Page !! Description\n'
     local out = '{| class="wikitable"\n! Page !! Description\n'


     for _, title in ipairs(list) do
     for _, line in ipairs(list) do
         title = mw.text.trim(title)
         line = mw.text.trim(line)


         if title ~= "" then
         if line ~= "" then
             local t = mw.title.new(title)
            -- Split "Page|Description"
             local desc = ""
             local parts = mw.text.split(line, "|")
            local title = mw.text.trim(parts[1] or "")
             local desc = mw.text.trim(parts[2] or "")


             if t and t.exists then
             -- Determine subpage depth
                -- Get SHORTDESC via page properties
            local depth = select(2, title:gsub("/", ""))
                local props = mw.title.new(title):getProperties()
            local indent = string.rep("— ", depth)
                if props and props.shortdesc then
                    desc = props.shortdesc
                end
            end


             out = out .. '|-\n| [[' .. title .. ']] || ' .. desc .. '\n'
            -- Output row
             out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n'
         end
         end
     end
     end

Revision as of 21:29, 10 April 2026

Documentation for this module may be created at Module:NamespaceTable/doc

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 _, line in ipairs(list) do
        line = mw.text.trim(line)

        if line ~= "" then
            -- Split "Page|Description"
            local parts = mw.text.split(line, "|")
            local title = mw.text.trim(parts[1] or "")
            local desc = mw.text.trim(parts[2] or "")

            -- Determine subpage depth
            local depth = select(2, title:gsub("/", ""))
            local indent = string.rep("— ", depth)

            -- Output row
            out = out .. '|-\n| ' .. indent .. '[[' .. title .. ']] || ' .. desc .. '\n'
        end
    end

    out = out .. '|}'
    return out
end

return p