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
Created page with "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 -- Determine the corresponding..."
 
m Gpe moved page Module:QuickCat to Module:CatType
(No difference)

Revision as of 13:14, 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

    -- Determine the corresponding "abilities" category
    local abilitiesCategory = baseCategory:gsub(type, "abilities")
    local abilitiesParents = mw.site.categories[abilitiesCategory] or {}

    local result = {}
    -- Add the immediate parent (abilities category)
    table.insert(result, "[[Category:" .. abilitiesCategory .. "]]")

    -- Add parent categories, replacing "abilities" with the detected type
    for _, parent in ipairs(abilitiesParents) do
        local replacement = parent:gsub("abilities", type)
        table.insert(result, "[[Category:" .. replacement .. "]]")
    end

    return table.concat(result, "\n")
end

return p