Jump to content

Module:ExternalLinks: Difference between revisions

From BadWolfMC Wiki
No edit summary
No edit summary
Line 31: Line 31:


     return string.format("[%s %s]", url, label)
     return string.format("[%s %s]", url, label)
end
function p.listKeys(frame)
    local out = {}
    for key, data in pairs(links) do
        table.insert(out, string.format("* <code>%s</code> – %s", key, data.label or data.url))
    end
    table.sort(out)
    return table.concat(out, "\n")
end
function p.listBareUrls(frame)
    local out = {}
    for key, data in pairs(links) do
        table.insert(out, string.format("* <code>%s</code> – %s", key, data.url))
    end
    table.sort(out)
    return table.concat(out, "\n")
end
end


return p
return p

Revision as of 23:44, 7 May 2025

This module defines a centralized table of commonly used external URLs for BadWolfMC.

It is invoked via the template Template:Ext-link using:

{{ext-link|key|optional display text}}
  1. Edit Module:ExternalLinks
  2. Add a new entry (preferably in alphabetical order) to the links table in this format:
    key = {
        url = "https://example.com/...",
        label = "Default Label"
    }
    
  3. Use it in the wiki like {{ext-link|key}}

See also


local links = {
    rp = {
        url = "https://example.com/resourcepack/latest.zip",
        label = "Resource Pack"
    },
    wiki = {
        url = "https://wiki.badwolfmc.com/",
        label = "BadWolfMC Wiki"
    },
    discord = {
        url = "https://discord.gg/examplecode",
        label = "Discord"
    },
    -- Add more aliases here
}

local p = {}

function p.link(frame)
    local args = frame:getParent().args -- get the calling template's args

    local key = args[1] or args["1"]
    local customLabel = args[2] or args["2"]

    if not key or not links[key] then
        return string.format("<strong class='error'>Invalid external link key: %s</strong>", key or "nil")
    end

    local url = links[key].url
    local label = customLabel or links[key].label or url

    return string.format("[%s %s]", url, label)
end

function p.listKeys(frame)
    local out = {}
    for key, data in pairs(links) do
        table.insert(out, string.format("* <code>%s</code> – %s", key, data.label or data.url))
    end
    table.sort(out)
    return table.concat(out, "\n")
end

function p.listBareUrls(frame)
    local out = {}
    for key, data in pairs(links) do
        table.insert(out, string.format("* <code>%s</code> – %s", key, data.url))
    end
    table.sort(out)
    return table.concat(out, "\n")
end

return p