Module:NarratorListModule: Difference between revisions
From The Seven Sages of Rome
Created page with "local p = {} local function getSubobjects(shortTitle) local query = "Has subobject::+Has Short Title::" .. shortTitle .. "|?Has Narrator" local results = mw.smw.ask(query) return results end function p.getNarratorList(frame) local shortTitle = frame.args.shortTitle if not shortTitle then return "Error: shortTitle parameter is missing." end local results = getSubobjects(shortTitle) local groupedResults = {} for _, result in ipairs(results..." |
No edit summary |
||
| Line 14: | Line 14: | ||
local results = getSubobjects(shortTitle) | local results = getSubobjects(shortTitle) | ||
if not results then -- Check if results is nil | |||
return "* No matching subobjects found." | |||
end | |||
local groupedResults = {} | local groupedResults = {} | ||
Revision as of 19:27, 27 February 2025
Documentation for this module may be created at Module:NarratorListModule/doc
local p = {}
local function getSubobjects(shortTitle)
local query = "[[Has subobject::+]][[Has Short Title::" .. shortTitle .. "]]|?Has Narrator"
local results = mw.smw.ask(query)
return results
end
function p.getNarratorList(frame)
local shortTitle = frame.args.shortTitle
if not shortTitle then
return "Error: shortTitle parameter is missing."
end
local results = getSubobjects(shortTitle)
if not results then -- Check if results is nil
return "* No matching subobjects found."
end
local groupedResults = {}
for _, result in ipairs(results) do
local narrator = result["Has Narrator"] and result["Has Narrator"][1]
if narrator then
if not groupedResults[narrator] then
groupedResults[narrator] = {}
end
groupedResults[narrator][#groupedResults[narrator] + 1] = result.fulltext
end
end
local output = {}
for narrator, pages in pairs(groupedResults) do
output[#output + 1] = "* " .. narrator .. ": " .. table.concat(pages, ", ")
end
return table.concat(output, "\n")
end
return p