More actions
Content deleted Content added
m Gpe moved page Module:QuickCat to Module:CatType |
No edit summary |
||
Line 10: | Line 10: | ||
-- Determine type (either "spells" or "skills") |
-- Determine type (either "spells" or "skills") |
||
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 |
||
return "Error: Unable to determine type ('spells' or 'skills') from category name." |
return "Error: Unable to determine type ('spells' or 'skills') from category name." |
||
end |
end |
||
-- |
-- Replace "spells" or "skills" with "abilities" to determine the immediate parent category |
||
local abilitiesCategory = baseCategory:gsub(type, "abilities") |
local abilitiesCategory = baseCategory:gsub(type, "abilities") |
||
local abilitiesParents = mw.site.categories[abilitiesCategory] or {} |
|||
-- Define the parent categories manually or infer based on naming patterns |
|||
local parentCategories = { |
|||
"Parent abilities", |
|||
"Grandparent abilities" |
|||
} |
|||
-- Generate the category tree, replacing "abilities" with the detected type |
|||
local result = {} |
local result = {} |
||
-- Add the immediate parent (abilities category) |
|||
table.insert(result, "[[Category:" .. abilitiesCategory .. "]]") |
table.insert(result, "[[Category:" .. abilitiesCategory .. "]]") |
||
⚫ | |||
local categoryWithReplacement = parent:gsub("abilities", type) |
|||
⚫ | |||
⚫ | |||
local replacement = parent:gsub("abilities", type) |
|||
⚫ | |||
end |
end |
||
Revision as of 13:16, 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 type (either "spells" or "skills")
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
-- Replace "spells" or "skills" with "abilities" to determine the immediate parent category
local abilitiesCategory = baseCategory:gsub(type, "abilities")
-- Define the parent categories manually or infer based on naming patterns
local parentCategories = {
"Parent abilities",
"Grandparent abilities"
}
-- Generate the category tree, replacing "abilities" with the detected type
local result = {}
table.insert(result, "[[Category:" .. abilitiesCategory .. "]]")
for _, parent in ipairs(parentCategories) do
local categoryWithReplacement = parent:gsub("abilities", type)
table.insert(result, "[[Category:" .. categoryWithReplacement .. "]]")
end
return table.concat(result, "\n")
end
return p