Module:Variants: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(Do not error when Variant name isn't defined) |
m (spaces to tabs) |
||
Line 12: | Line 12: | ||
local variant_name = args.variant or mw.title.getCurrentTitle().fullText |
local variant_name = args.variant or mw.title.getCurrentTitle().fullText |
||
local query = { |
local query = { |
||
'[[Variant of::'..variant_name..']]', |
|||
'?Profession A #', -- Adding a # to this query makes it return plaintext instead of a link |
|||
'?Profession B #', |
|||
'?Profession Level A', |
|||
'?Profession Level B', |
|||
'?Profession Level A High', |
|||
'?Profession Level B High', |
|||
'?Variant name', |
|||
get_images and '?Image#64px;x64px = Image' or nil, |
|||
limit = args.limit or 500, |
|||
} |
|||
} |
|||
local smw_data = mw.smw.ask(query) |
local smw_data = mw.smw.ask(query) |
||
if not smw_data then |
if not smw_data then |
||
Line 35: | Line 35: | ||
local contents |
local contents |
||
if smw_data then |
if smw_data then |
||
local formatted = {} |
|||
for _, entry in ipairs(smw_data) do |
|||
if entry['Variant name'] then |
|||
local page = entry[1] |
|||
local pipe = page:find('|') |
|||
if pipe then |
|||
page = page:sub(3, pipe-1) |
|||
else |
|||
page = page:sub(3, -3) |
|||
end |
|||
table.insert(formatted, ('[[%s|%s]]'):format(page, entry['Variant name'])) |
|||
else |
|||
table.insert(formatted, entry[1]) |
|||
end |
|||
end |
|||
end |
|||
contents = table.concat(formatted, ' • ') |
contents = table.concat(formatted, ' • ') |
||
else |
else |