Module:PageNotice: Difference between revisions

From Candypedia
Created page with "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" } for category, notice in pairs(categories) do if mw.title.getCurrentTitle():inCategory(category) then return frame:expandTemplate{ title = notice } end end retur..."
 
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 8: Line 8:
         ["Raw LLM output"] = "Notice LLM raw"
         ["Raw LLM output"] = "Notice LLM raw"
     }
     }
    local title = mw.title.getCurrentTitle()
    if not title then
        return ""
    end
    -- Fetch the wikitext of the current page
    local content = title:getContent()
    if not content then
        return ""
    end


     for category, notice in pairs(categories) do
     for category, notice in pairs(categories) do
         if mw.title.getCurrentTitle():inCategory(category) then
         if string.find(content, "%[%[Category:" .. category .. "%]%]") then
             return frame:expandTemplate{ title = notice }
             return frame:expandTemplate{ title = notice }
         end
         end

Latest revision as of 10:07, 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

    -- Fetch the wikitext of the current page
    local content = title:getContent()
    if not content then
        return ""
    end

    for category, notice in pairs(categories) do
        if string.find(content, "%[%[Category:" .. category .. "%]%]") then
            return frame:expandTemplate{ title = notice }
        end
    end

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

return p