Actions

Module

Module:RandomPage

From Dune Awakening DB

Revision as of 23:22, 21 May 2025 by Operator (talk | contribs) (Created page with "-- 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 -- Bui...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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