More actions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 29: | Line 29: | ||
-- Replace every instance of "abilities]]" with the detected type (e.g., "spells]]" or "skills]]") |
-- Replace every instance of "abilities]]" with the detected type (e.g., "spells]]" or "skills]]") |
||
local updatedContent = parentContent:gsub(" |
local updatedContent = parentContent:gsub("Abilities%]%]", type:gsub("spells", "Spells"):gsub("skills", "Skills")) |
||
local updatedContent = updatedContent:gsub("abilities%]%]", type .. "]]") |
|||
-- Return the updated content |
-- Return the updated content |
Revision as of 13:30, 12 January 2025
Documentation for this module may be created at Module:CatType/doc
local p = {}
function p.generateCategories(frame)
local baseCategory = frame.args[1] or ""
if baseCategory == "" then
return "Error: No base category provided."
end
-- Determine the type based on the base category name
local type = baseCategory:match("spells") or baseCategory:match("skills")
if not type then
return "Error: Unable to determine type ('spells' or 'skills') from category name."
end
-- Determine the parent category by replacing the detected type with "abilities"
local parentCategory = "Category:" .. baseCategory:gsub(type, "abilities")
-- Attempt to retrieve the content of the parent category
local parentPage = mw.title.new(parentCategory)
if not parentPage then
return "Error: Unable to access the parent category page object: " .. parentCategory
end
local parentContent = parentPage:getContent()
if not parentContent then
return "Error: Unable to retrieve the content of the parent category: " .. parentCategory
end
-- Replace every instance of "abilities]]" with the detected type (e.g., "spells]]" or "skills]]")
local updatedContent = parentContent:gsub("Abilities%]%]", type:gsub("spells", "Spells"):gsub("skills", "Skills"))
local updatedContent = updatedContent:gsub("abilities%]%]", type .. "]]")
-- Return the updated content
return "[[" .. parentCategory .. "]]" .. updatedContent
end
return p