Module:PageNotice: Difference between revisions

From Candypedia
No edit summary
No edit summary
Line 10: Line 10:


     local title = mw.title.getCurrentTitle()
     local title = mw.title.getCurrentTitle()
     local pageCategories = title and title:getCategories() or {}
     if not title then
        return ""
    end


     for category in pairs(pageCategories) do
    -- Get the current page's categories as text
         if categories[category] then
    local pageCategories = mw.site.categories and mw.site.categories() or {}
             return frame:expandTemplate{ title = categories[category] }
 
     for _, category in ipairs(pageCategories) do
        local categoryName = category.text
         if categories[categoryName] then
             return frame:expandTemplate{ title = categories[categoryName] }
         end
         end
     end
     end

Revision as of 10:06, 31 May 2024

Documentation for this module may be created at Module:PageNotice/doc

local p = {}

function p.checkCategory(frame)
    local categories = {
        ["Needs Polish"] = "Notice Needs Polish",
        ["Stub"] = "Notice Stub",
        ["Stub for LLM content"] = "Notice Stub for LLM content",
        ["Raw LLM output"] = "Notice LLM raw"
    }

    local title = mw.title.getCurrentTitle()
    if not title then
        return ""
    end

    -- Get the current page's categories as text
    local pageCategories = mw.site.categories and mw.site.categories() or {}

    for _, category in ipairs(pageCategories) do
        local categoryName = category.text
        if categories[categoryName] then
            return frame:expandTemplate{ title = categories[categoryName] }
        end
    end

    return ""  -- Return an empty string if no category matches
end

return p