Module:ExternalLinks: Difference between revisions
Appearance
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 71: | Line 71: | ||
local label = customLabel or links[key].label or url | local label = customLabel or links[key].label or url | ||
return string.format( | return string.format("[%s %s]", url, label) | ||
end | end | ||
Revision as of 09:50, 9 May 2025
Module:ExternalLinks
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}}
How to add a new link
- Edit Module:ExternalLinks
- Add a new entry (preferably in alphabetical order) to the
linkstable in this format:key = { url = "https://example.com/...", label = "Default Label" }
- Use it in the wiki like
{{ext-link|key}}
See also
local links = {
apply = {
url = "https://www.badwolfmc.com/membership-application/",
label = "Apply"
},
discord = {
url = "https://discord.badwolfmc.com",
label = "Discord"
},
mapalpha = {
url = "https://alpha.badwolfmc.com",
label = "Alpha Map"
},
mapbeta = {
url = "https://beta.badwolfmc.com",
label = "Beta Map"
},
mapgamma = {
url = "https://gamma.badwolfmc.com",
label = "Gamma Map"
},
mapdelta = {
url = "https://delta.badwolfmc.com",
label = "Delta Map"
},
news = {
url = "https://www.badwolfmc.com/news/",
label = "News"
},
rp = {
url = "https://magic.badwolfmc.com/rp/BadWolfMC-RP-10-3-SNAPSHOT-3.zip",
label = "Resource Pack"
},
rules = {
url = "https://www.badwolfmc.com/server-rules/",
label = "Server Rules"
},
shop = {
url = "https://www.badwolfmc.com/shop/",
label = "BadWolfMC Shop"
},
stats = {
url = "https://stats.badwolfmc.com/",
label = "Player Stats"
},
status = {
url = "https://status.badwolfmc.com/",
label = "Uptime Status"
},
wiki = {
url = "https://wiki.badwolfmc.com/",
label = "BadWolfMC Wiki"
},
-- 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