Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:CatType: Difference between revisions

From Teriock
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


-- Determine the corresponding "abilities" category
-- 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 .. "]]")
for _, parent in ipairs(parentCategories) do

-- Add parent categories, replacing "abilities" with the detected type
local categoryWithReplacement = parent:gsub("abilities", type)
table.insert(result, "[[Category:" .. categoryWithReplacement .. "]]")
for _, parent in ipairs(abilitiesParents) do
local replacement = parent:gsub("abilities", type)
table.insert(result, "[[Category:" .. replacement .. "]]")
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