Actions

Module

Module:RandomPage

From Dune Awakening DB

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

-- Module:RandomPage
local p = {}

-- Returns a random page from a given category wrapped in a card template
function p.randomCard(frame)
    local cat = frame.args.category or "Lore"
    local t   = frame.args.template or "DuneCard"

    -- Query categorymembers
    local pages = mw.site.stats.pagesInCategory(cat, "pages")
    if pages == 0 then return "" end
    local rnd   = math.random(pages)
    local title = mw.site.getCategory(cat):members()[rnd].title

    -- Build card
    return string.format(
        "{{%s|title=%s|text=%s|link=[[ %s ]] }}",
        t,
        title.text,
        "Dive deeper into the lore.",
        title.prefixedText
    )
end

return p