Module:GTAthumb

From GTA BOOM Wiki

Renders an article thumb.


local p = {}

function p.latestNewsItem(frame)
    local args = frame:getParent().args
    local news = args.News or ""
    local excerpt = args.Excerpt or ""
    local author = args.Author or ""
    local suppressAvatar = args["suppress avatar"] or ""
    local datePublished = args["Date published"] or ""

    -- Fetch image for news
    local imageFeatured = frame:preprocess("{{#show:" .. news .. "|?Image featured|link=none|default=no-photo.webp}}")
    local imagePagename = frame:preprocess("{{PAGENAME:" .. imageFeatured .. "}}")

    -- Build the HTML structure
    local html = mw.html.create("div")
    html:addClass("latest-news-item d-flex flex-column mb-4")

    -- Image
    local imageDiv = html:tag("div")
        :addClass("latest-news-image")
        :wikitext("[[File:" .. imagePagename .. "|link=" .. news .. "|class=w-100 object-fit notpageimage|800px]]")

    -- Header
    local headerDiv = html:tag("div")
        :addClass("latest-news-header")
        :wikitext("[[" .. news .. "]]")

    -- Excerpt (if present)
    if excerpt ~= "" then
        html:tag("div")
            :addClass("py-1 mb-2 text-muted small")
            :wikitext(excerpt)
    end

    -- Author and additional info (if present)
    if author ~= "" then
        local latestNewsInfo = html:tag("div")
            :addClass("latest-news-info")

        if suppressAvatar ~= "1" then
            local avatar = frame:preprocess("{{#ask: [[File:+]] [[~" .. frame:preprocess("{{PAGENAME:" .. author .. "}}") .. ".*]] |limit=1|searchlabel=|default=[[File:No-photo.webp|class=notpageimage]]}}")
            latestNewsInfo:tag("div")
                :addClass("author-avatar")
                :wikitext(avatar)
        end

        local revisionInfo = latestNewsInfo:tag("div")
            :addClass("revision-info small")
        revisionInfo:wikitext("By [[User:" .. frame:preprocess("{{PAGENAME:" .. author .. "}}") .. "]] ")
        revisionInfo:wikitext(frame:preprocess("{{#timel: F j, Y|" .. datePublished .. "}}"))
    end

    return tostring(html)
end

return p