Module:SocialMedia: Difference between revisions

No edit summary
No edit summary
Line 28: Line 28:
     },
     },
     {
     {
         param  = "mastodon",
         param  = "telegram",
         icon  = "File:SocialMastodonIcon.png",
         icon  = "File:SocialTelegramIcon.png",
         prefix = "",
         prefix = "https://t.me/",
         label  = "Mastodon"
         label  = "Telegram"
     },
     },
     {
     {
Line 93: Line 93:
         local handle = getUserHandle(args, platform.param)
         local handle = getUserHandle(args, platform.param)
         if handle and handle ~= "" then
         if handle and handle ~= "" then
             local url
             local url = platform.prefix .. handle
 
            -- Mastodon is special; editor might type a full URL or just user@instance
            if type(platform.param) == "string" and platform.param == "mastodon"
              or type(platform.param) == "table" and table.concat(platform.param, ","):match("mastodon") then
 
                -- If editor typed a full URL
                if handle:match("^https?://") then
                    url = handle
                else
                    -- parse e.g. "icann@mastodon.social"
                    local domain = handle:match("@([^@]+)$") or "mastodon.social"
                    local user  = handle:match("^(.-)@") or handle
                    url = "https://" .. domain .. "/@" .. user
                end
            else
                -- For all other platforms, just prefix + handle
                url = platform.prefix .. handle
            end
 
             -- Build an icon link, passing label as alt text
             -- Build an icon link, passing label as alt text
             local iconLink = buildIconLink(platform.icon, platform.label, url)
             local iconLink = buildIconLink(platform.icon, platform.label, url)