my website
1---
2import IconCoffee from "./icons/IconCoffee.astro";
3import IconDocument from "./icons/IconDocument.astro";
4import IconEmail from "./icons/IconEmail.astro";
5import IconExternalLink from "./icons/IconExternalLink.astro";
6import IconGithub from "./icons/IconGithub.astro";
7import IconLinkedIn from "./icons/IconLinkedIn.astro";
8import IconMastodon from "./icons/IconMastodon.astro";
9import IconRssFeed from "./icons/IconRssFeed.astro";
10
11export interface Props {
12 link: string;
13}
14
15const { link } = Astro.props;
16
17const url = new URL(link, "https://i.rock");
18
19const fedi = new Set(["mas.to", "mastodon.social"] as const);
20type FediType = typeof fedi extends Set<infer A> ? A : never;
21
22const allowed = new Set([
23 "email",
24 "buymeacoffee.com",
25 "github.com",
26 "twitter.com",
27 "instagram.com",
28 "linkedin.com",
29 "fedi",
30 "external",
31 "document",
32 "rss",
33] as const);
34export type DomainType = typeof allowed extends Set<infer A> ? A : never;
35
36let type: DomainType = "external";
37
38if (url.pathname.endsWith(".pdf")) {
39 type = "document";
40} else if (url.protocol === "mailto:") {
41 type = "email";
42} else {
43 type = url.hostname.replace(/^www\./, "") as DomainType;
44 if (fedi.has(type as FediType)) type = "fedi";
45}
46
47if (!allowed.has(type)) type = "external";
48---
49
50{type === "buymeacoffee.com" && <IconCoffee />}
51
52{type === "document" && <IconDocument />}
53
54{type === "email" && <IconEmail />}
55
56{type === "external" && <IconExternalLink />}
57
58{type === "github.com" && <IconGithub />}
59
60{type === "linkedin.com" && <IconLinkedIn />}
61
62{type === "fedi" && <IconMastodon />}
63
64{type === "rss" && <IconRssFeed />}