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

Module:Number of works

From ProleWiki, the proletarian encyclopedia
Revision as of 15:05, 14 September 2024 by CriticalResist (talk | contribs)
local p = {}

-- Function to get the number of works using a parser function
function p.getWorkCount(frame)
    local category = frame.args.category or ''
    if category == '' then return "0 works" end

    -- Use the PAGESINCATEGORY parser function
    local pages = frame:preprocess('{{PAGESINCATEGORY:' .. category .. '}}')

    -- Return the result formatted
    local result = ''
    if tonumber(pages) == 1 then
        result = "1 work"
    else
        result = pages .. " works"
    end

    return result
end

function p.main(frame)
    return p.getWorkCount(frame)
end

return p