Jump to content

Module:ExternalLink: Difference between revisions

From Archono Database
Created title fetching system
 
No edit summary
Line 10: Line 10:
     })
     })


     if data and data[1] then
     local body = data[1]  
   
    if type(body) == 'string' then
         local body = data[1]
         local body = data[1]
         local title = body:match("<title>(.-)</title>")
         local title = body:match("<title>(.-)</title>")

Revision as of 08:16, 30 April 2026

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 = mw.ext.externalData.getExternalData({  -- Requires External Data extension
        url = webpage,
        format = 'html'
    })

    local body = data[1] 
    
    if type(body) == 'string' then
        local body = data[1]
        local title = body:match("<title>(.-)</title>")
        return title or webpage
    else
        return webpage .. " (fetching failed via External Data)"
    end
end

return p