--- import IconCoffee from "./icons/IconCoffee.astro"; import IconDocument from "./icons/IconDocument.astro"; import IconEmail from "./icons/IconEmail.astro"; import IconExternalLink from "./icons/IconExternalLink.astro"; import IconGithub from "./icons/IconGithub.astro"; import IconLinkedIn from "./icons/IconLinkedIn.astro"; import IconMastodon from "./icons/IconMastodon.astro"; import IconRssFeed from "./icons/IconRssFeed.astro"; export interface Props { link: string; } const { link } = Astro.props; const url = new URL(link, "https://i.rock"); const fedi = new Set(["mas.to", "mastodon.social"] as const); type FediType = typeof fedi extends Set ? A : never; const allowed = new Set([ "email", "buymeacoffee.com", "github.com", "twitter.com", "instagram.com", "linkedin.com", "fedi", "external", "document", "rss", ] as const); export type DomainType = typeof allowed extends Set ? A : never; let type: DomainType = "external"; if (url.pathname.endsWith(".pdf")) { type = "document"; } else if (url.protocol === "mailto:") { type = "email"; } else { type = url.hostname.replace(/^www\./, "") as DomainType; if (fedi.has(type as FediType)) type = "fedi"; } if (!allowed.has(type)) type = "external"; --- {type === "buymeacoffee.com" && } {type === "document" && } {type === "email" && } {type === "external" && } {type === "github.com" && } {type === "linkedin.com" && } {type === "fedi" && } {type === "rss" && }