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

Module:SummarySnippet

From The Fortune Bringers
Revision as of 01:05, 25 May 2025 by Dweller (talk | contribs)

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

local p = {}

function p.fromPage(frame)
    local input = frame.args[1] or ""
    
    -- Extract and clean up the title from [[Page]] or [[Page|Display]]
    local raw = mw.ustring.match(input, "%[%[(.-)%]%]") or input
    local titleText = mw.text.split(raw, "|")[1]
    
    -- Resolve title object
    local title = mw.title.new(titleText)
    
    if not title then
        return "Invalid page title: " .. titleText
    end

    -- Get content and return preview if it exists
    if title.exists then
        local content = title:getContent()
        if content then
            local preview = mw.ustring.sub(content, 1, 150)
            return preview .. "..."
        else
            return "No content on: " .. title.fullText
        end
    else
        return "Page does not exist: " .. titleText
    end
end

return p