2024-02-25 14:27:54 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module LinkHelper
|
|
|
|
DECORATABLE_DOMAINS = [
|
|
|
|
"e621.net",
|
|
|
|
#
|
|
|
|
# Aggregators
|
|
|
|
"linktr.ee",
|
|
|
|
"carrd.co",
|
|
|
|
#
|
|
|
|
# Art sites
|
|
|
|
"artfight.net",
|
|
|
|
"artstation.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"archiveofourown.org",
|
2024-02-25 14:27:54 -05:00
|
|
|
"aryion.com",
|
|
|
|
"derpibooru.org",
|
|
|
|
"deviantart.com",
|
|
|
|
"furaffinity.net",
|
|
|
|
"furrynetwork.com",
|
|
|
|
"furrystation.com",
|
|
|
|
"hentai-foundry.com",
|
|
|
|
"hiccears.com",
|
|
|
|
"imgur.com",
|
|
|
|
"inkbunny.net",
|
|
|
|
"itaku.ee",
|
|
|
|
"pillowfort.social",
|
|
|
|
"pixiv.net",
|
|
|
|
"skeb.jp",
|
|
|
|
"sofurry.com",
|
|
|
|
"toyhou.se",
|
|
|
|
"tumblr.com",
|
|
|
|
"newgrounds.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"yiff.life",
|
2024-02-25 14:27:54 -05:00
|
|
|
"weasyl.com",
|
|
|
|
"webtoons.com",
|
|
|
|
#
|
|
|
|
# Social media
|
|
|
|
"aethy.com",
|
|
|
|
"bsky.app",
|
2024-02-28 11:55:00 -05:00
|
|
|
"blogspot.com",
|
2024-02-25 14:27:54 -05:00
|
|
|
"cohost.org",
|
|
|
|
"facebook.com",
|
|
|
|
"instagram.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"mastodon.social",
|
|
|
|
"nijie.info",
|
2024-02-25 14:27:54 -05:00
|
|
|
"pawoo.net",
|
|
|
|
"plurk.com",
|
|
|
|
"privatter.net",
|
|
|
|
"reddit.com",
|
|
|
|
"tiktok.com",
|
|
|
|
"twitter.com",
|
|
|
|
"vk.com",
|
|
|
|
"weibo.com",
|
|
|
|
"youtube.com",
|
|
|
|
#
|
|
|
|
# Livestreams
|
|
|
|
"picarto.tv",
|
|
|
|
"piczel.tv",
|
|
|
|
"twitch.tv",
|
|
|
|
#
|
|
|
|
# Paysites
|
|
|
|
"artconomy.com",
|
|
|
|
"boosty.to",
|
|
|
|
"buymeacoffee.com",
|
|
|
|
"commishes.com",
|
|
|
|
"gumroad.com",
|
|
|
|
"etsy.com",
|
|
|
|
"fanbox.cc",
|
|
|
|
"itch.io",
|
|
|
|
"ko-fi.com",
|
|
|
|
"patreon.com",
|
|
|
|
"redbubble.com",
|
|
|
|
"subscribestar.adult",
|
|
|
|
#
|
|
|
|
# Bulk storage
|
|
|
|
"amazonaws.com",
|
|
|
|
"catbox.moe",
|
|
|
|
"drive.google.com",
|
|
|
|
"dropbox.com",
|
|
|
|
"mega.nz",
|
|
|
|
"onedrive.live.com",
|
|
|
|
#
|
|
|
|
# Imageboards
|
|
|
|
"4chan.org",
|
|
|
|
"danbooru.donmai.us",
|
|
|
|
"desuarchive.org",
|
|
|
|
"e-hentai.org",
|
2024-02-28 11:55:00 -05:00
|
|
|
"furbooru.org",
|
2024-02-25 14:27:54 -05:00
|
|
|
"gelbooru.com",
|
|
|
|
"rule34.paheal.net",
|
|
|
|
"rule34.xxx",
|
|
|
|
"u18chan.com",
|
|
|
|
#
|
|
|
|
# Other
|
|
|
|
"curiouscat.me",
|
|
|
|
"discord.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"fandom.com",
|
|
|
|
"f-list.net",
|
2024-02-25 14:27:54 -05:00
|
|
|
"steamcommunity.com",
|
|
|
|
"t.me",
|
|
|
|
"trello.com",
|
|
|
|
"web.archive.org",
|
2024-02-28 11:55:00 -05:00
|
|
|
"wordpress.com",
|
|
|
|
"wikimedia.org",
|
2024-02-25 14:27:54 -05:00
|
|
|
].freeze
|
|
|
|
|
|
|
|
DECORATABLE_ALIASES = {
|
|
|
|
# alt names
|
2024-02-28 11:55:00 -05:00
|
|
|
"archiveofourown.com" => "archiveofourown.org",
|
|
|
|
"curiouscat.live" => "curiouscat.me",
|
2024-02-25 14:27:54 -05:00
|
|
|
"e926.net" => "e621.net",
|
2024-02-28 11:55:00 -05:00
|
|
|
"exhentai.org" => "e-hentai.org",
|
2024-02-25 14:27:54 -05:00
|
|
|
"discord.gg" => "discord.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"pillowfort.io" => "pillowfort.social",
|
2024-02-25 14:27:54 -05:00
|
|
|
"pixiv.me" => "pixiv.net",
|
2024-02-28 11:55:00 -05:00
|
|
|
"subscribestar.com" => "subscribestar.adult",
|
|
|
|
"wikia.com" => "fandom.com",
|
2024-02-25 14:27:54 -05:00
|
|
|
"x.com" => "twitter.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"youtu.be" => "youtube.com",
|
2024-02-25 14:27:54 -05:00
|
|
|
|
|
|
|
# same icon
|
2024-02-28 11:55:00 -05:00
|
|
|
"baraag.net" => "mastodon.social",
|
2024-02-25 14:27:54 -05:00
|
|
|
"cloudfront.net" => "amazonaws.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"mastodon.art" => "mastodon.social",
|
|
|
|
"meow.social" => "mastodon.social",
|
2024-02-25 14:27:54 -05:00
|
|
|
"sta.sh" => "deviantart.com",
|
|
|
|
|
|
|
|
# image servers
|
|
|
|
"4cdn.org" => "4chan.org",
|
2024-02-28 11:55:00 -05:00
|
|
|
"cohostcdn.org" => "cohost.org",
|
2024-02-25 14:27:54 -05:00
|
|
|
"discordapp.com" => "discord.com",
|
|
|
|
"derpicdn.net" => "derpibooru.org",
|
|
|
|
"deviantart.net" => "deviantart.com",
|
|
|
|
"dropboxusercontent.com" => "dropbox.com",
|
|
|
|
"facdn.net" => "furaffinity.net",
|
|
|
|
"fbcdn.net" => "facebook.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"furrycdn.org" => "furbooru.org",
|
2024-02-25 14:27:54 -05:00
|
|
|
"ib.metapix.net" => "inkbunny.net",
|
|
|
|
"ngfiles.com" => "newgrounds.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"patreonusercontent.com" => "patreon.com",
|
2024-02-25 14:27:54 -05:00
|
|
|
"pximg.net" => "pixiv.net",
|
|
|
|
"redd.it" => "reddit.com",
|
2024-02-28 11:55:00 -05:00
|
|
|
"sofurryfiles.com" => "sofurry.com",
|
|
|
|
"static.wikia.nocookie.net" => "fandom.com",
|
2024-02-25 14:27:54 -05:00
|
|
|
"twimg.com" => "twitter.com",
|
|
|
|
"ungrounded.net" => "newgrounds.com",
|
|
|
|
"wixmp.com" => "deviantart.com",
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def decorated_link_to(text, path, **)
|
|
|
|
link_to(path, class: "decorated", **) do
|
|
|
|
favicon_for_link(path) + text
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def favicon_for_link(path)
|
|
|
|
hostname = hostname_for_link(path)
|
2024-02-27 09:48:52 -05:00
|
|
|
if hostname
|
|
|
|
tag.img(
|
|
|
|
class: "link-decoration",
|
|
|
|
src: asset_pack_path("static/#{hostname}.png"),
|
|
|
|
data: {
|
|
|
|
hostname: hostname,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
else
|
|
|
|
tag.i(
|
|
|
|
class: "fa-solid fa-globe link-decoration",
|
|
|
|
data: { hostname: "none" },
|
|
|
|
)
|
|
|
|
end
|
2024-02-25 14:27:54 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def hostname_for_link(path)
|
|
|
|
begin
|
2024-03-18 13:59:19 -04:00
|
|
|
uri = Addressable::URI.parse(path)
|
|
|
|
rescue Addressable::URI::InvalidURIError
|
2024-02-27 09:48:52 -05:00
|
|
|
return nil
|
2024-02-25 14:27:54 -05:00
|
|
|
end
|
2024-02-27 09:48:52 -05:00
|
|
|
return nil unless uri.host
|
2024-02-25 14:27:54 -05:00
|
|
|
|
|
|
|
hostname = uri.host.delete_prefix("www.")
|
|
|
|
|
|
|
|
# 1: direct match
|
|
|
|
return hostname if DECORATABLE_DOMAINS.include?(hostname)
|
|
|
|
|
|
|
|
# 2: aliases
|
|
|
|
return DECORATABLE_ALIASES[hostname] if DECORATABLE_ALIASES[hostname]
|
|
|
|
|
|
|
|
# 3: Try the same, this time with the leftmost subdomain removed
|
|
|
|
if hostname.count(".") > 1
|
|
|
|
_removed, remaining_hostname = hostname.split(".", 2)
|
|
|
|
return remaining_hostname if DECORATABLE_DOMAINS.include?(remaining_hostname)
|
2024-02-27 09:48:52 -05:00
|
|
|
DECORATABLE_ALIASES[remaining_hostname]
|
2024-02-25 14:27:54 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|