Module:CiteTweet

From HFGCS Wiki
Revision as of 22:07, 8 December 2025 by Maintenance script (talk | contribs) (Remove ref tag generation - template should only return citation text, not wrap in ref tags)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This module is invoked by Template:Cite tweet to parse post authors.


local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local url = args.url or args[1] or ""
    local author = args.author or ""
    local date = args.date or ""

    -- Validate URL
    if url == "" then
        return '<span style="color:red;">Error: URL required</span>'
    end

    -- Parse author from URL if not provided
    if author == "" then
        author = url:match("x%.com/([^/]+)/status/") or url:match("twitter%.com/([^/]+)/status/")

        if not author then
            return '<span style="color:red;">Error: Could not parse username from URL. Please provide author parameter.</span>'
        end
    end

    -- Build output
    local output = url .. ", [https://www.x.com/" .. author .. " @" .. author .. "] Twitter post"

    if date ~= "" then
        output = output .. ", " .. date
    end

    output = output .. "."

    return output
end

return p