Jump to content

Module:SubpageLinks

From Drifters Almanac

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

local p = {}

function p.fromDelimited(frame)
    local raw = frame.args[1] or ""
    local delimiter = frame.args.delimiter or ","
    local list = mw.text.split(raw, delimiter)
    local output = {}

    table.insert(output, '<ul style="margin-left: 1em;">')
    for _, item in ipairs(list) do
        item = mw.text.trim(item)
        if item ~= "" then
            local label
            local target = item

            -- If it has a /, treat it as "Name/Zone" → "Name (Zone)"
            local base, zone = string.match(item, "^(.-)/(.+)$")
            if base and zone then
                label = base .. " (" .. zone .. ")"
            else
                label = item
            end

            table.insert(output, string.format('<li>[[%s|%s]]</li>', target, label))
        end
    end
    table.insert(output, '</ul>')

    return table.concat(output, "\n")
end

return p