Module:SmartMobLinks: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p. | -- Returns a table of rows { target, label, exists, form } | ||
function p.parseMobList(frame) | |||
local raw = frame.args[1] or "" | local raw = frame.args[1] or "" | ||
local delimiter = frame.args.delimiter or "," | local delimiter = frame.args.delimiter or "," | ||
local items = mw.text.split(raw, delimiter) | local items = mw.text.split(raw, delimiter) | ||
local | local result = {} | ||
for _, fullPath in ipairs(items) do | for _, fullPath in ipairs(items) do | ||
| Line 16: | Line 15: | ||
local label = fullPath | local label = fullPath | ||
if not prefix or not rest then | if not prefix or not rest then | ||
prefix = nil | prefix = nil | ||
| Line 22: | Line 20: | ||
end | end | ||
if prefix == "Mob" then | if prefix == "Mob" then | ||
local base, zone = string.match(rest, "^(.-)/(.+)$") | local base, zone = string.match(rest, "^(.-)/(.+)$") | ||
| Line 33: | Line 30: | ||
label = rest | label = rest | ||
else | else | ||
label = rest | label = rest | ||
end | end | ||
local | local exists = false | ||
local title = mw.title.new(fullPath) | |||
if | if title and title.exists then | ||
exists = true | |||
end | |||
local form = (prefix == "Named Mob") and "NamedMob" or "Mob" | |||
table.insert(result, string.format("%s||%s||%s||%s", fullPath, label, tostring(exists), form)) | |||
end | end | ||
end | end | ||
return table.concat(result, "\n") | |||
return table.concat( | |||
end | end | ||
return p | return p | ||
Revision as of 22:41, 12 May 2025
Documentation for this module may be created at Module:SmartMobLinks/doc
local p = {}
-- Returns a table of rows { target, label, exists, form }
function p.parseMobList(frame)
local raw = frame.args[1] or ""
local delimiter = frame.args.delimiter or ","
local items = mw.text.split(raw, delimiter)
local result = {}
for _, fullPath in ipairs(items) do
fullPath = mw.text.trim(fullPath)
if fullPath ~= "" then
local prefix, rest = string.match(fullPath, "^(.-)/(.+)$")
local label = fullPath
if not prefix or not rest then
prefix = nil
rest = fullPath
end
if prefix == "Mob" then
local base, zone = string.match(rest, "^(.-)/(.+)$")
if base and zone then
label = base .. " (" .. zone .. ")"
else
label = rest
end
elseif prefix == "Named Mob" then
label = rest
else
label = rest
end
local exists = false
local title = mw.title.new(fullPath)
if title and title.exists then
exists = true
end
local form = (prefix == "Named Mob") and "NamedMob" or "Mob"
table.insert(result, string.format("%s||%s||%s||%s", fullPath, label, tostring(exists), form))
end
end
return table.concat(result, "\n")
end
return p