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

Module:CiteTweet: Difference between revisions

From HFGCS Wiki
Jump to navigation Jump to search
Create Lua module to parse Twitter usernames from URLs and format citations
 
(No difference)

Latest revision as of 00:00, 7 December 2025

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