Jump to content

Module:ExternalLink

From Archono Database
Revision as of 08:21, 30 April 2026 by NonaSoft (talk | contribs) (Rewritten using Claude (dont really have the time for this))

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

local p = {}

p.GetTitle = function(frame)
    local webpage = frame.args[1]
    if not webpage then return "No link provided" end

    local data, err = mw.ext.externalData.getExternalData(
        "url=" .. webpage,
        "format=pre",
        "data=page_content"
    )
    
    if not data then
        return "Fetch failed: " .. tostring(err)
    end

    local content = data["page_content"] and data["page_content"][1]

    if type(content) ~= "string" then
        return "Unexpected data type: " .. type(content)
    end

     local title = content:match("<[Tt][Ii][Tt][Ll][Ee]>(.-)</%1>")
                  or content:match("<title>(.-)</title>")

    return title and mw.text.trim(title) or webpage
end

return p