More actions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
end |
end |
||
-- Determine type |
-- Determine the type based on the base category name |
||
local type = baseCategory:match("spells") or baseCategory:match("skills") |
local type = baseCategory:match("spells") or baseCategory:match("skills") |
||
if not type then |
if not type then |
||
Line 14: | Line 14: | ||
end |
end |
||
⚫ | |||
-- Replace "spells" or "skills" with "abilities" to determine the immediate parent category |
|||
local |
local parentCategory = baseCategory:gsub(type, "abilities") |
||
-- |
-- Get the content of the parent category |
||
local parentContent = mw.title.new(parentCategory):getContent() |
|||
local parentCategories = { |
|||
if not parentContent then |
|||
"Parent abilities", |
|||
return "Error: Unable to retrieve the content of the parent category: " .. parentCategory |
|||
"Grandparent abilities" |
|||
end |
|||
-- Extract categories from the parent category's content |
|||
⚫ | |||
local |
local categories = {} |
||
for category in parentContent:gmatch("%[%[Category:([^\]]+)%]%]") do |
|||
table.insert(result, "[[Category:" .. abilitiesCategory .. "]]") |
|||
-- Replace "abilities" with the detected type in each category |
|||
for _, parent in ipairs(parentCategories) do |
|||
local |
local updatedCategory = category:gsub("abilities", type) |
||
table.insert( |
table.insert(categories, "[[Category:" .. updatedCategory .. "]]") |
||
end |
end |
||
-- Return the updated categories as a newline-separated string |
|||
return table.concat( |
return table.concat(categories, "\n") |
||
end |
end |
||
Revision as of 13:17, 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 = baseCategory:gsub(type, "abilities")
-- Get the content of the parent category
local parentContent = mw.title.new(parentCategory):getContent()
if not parentContent then
return "Error: Unable to retrieve the content of the parent category: " .. parentCategory
end
-- Extract categories from the parent category's content
local categories = {}
for category in parentContent:gmatch("%[%[Category:([^\]]+)%]%]") do
-- Replace "abilities" with the detected type in each category
local updatedCategory = category:gsub("abilities", type)
table.insert(categories, "[[Category:" .. updatedCategory .. "]]")
end
-- Return the updated categories as a newline-separated string
return table.concat(categories, "\n")
end
return p