HFGCS Wiki softlaunch is expected late December 2024 or else January 2025.

Module:CiteTweet

From HFGCS Wiki
Jump to navigation Jump to search

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

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
        -- Try to extract username from x.com/username/status/... or twitter.com/username/status/...
        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