Dough Git

clove/pkviewer

web/src/lib/components/SocialLinks.svelte

back to web/src/lib/components

<!-- web/src/lib/components/SocialLinks.svelte -->
<script lang="ts">
  import type { SocialLink } from "@pkviewer/shared";
  import type { IconName } from "$lib/icons.ts";
  import Icon from "./Icon.svelte";

  // Rendered as links and never fetched server-side: a user-supplied URL is an SSRF vector
  let { links }: { links: SocialLink[] } = $props();

  const ICONS: Record<string, IconName> = {
    discord: "discord",
    github: "github",
    mastodon: "mastodon",
    twitch: "twitch",
    youtube: "youtube",
    website: "globe",
  };
</script>

{#if links.length > 0}
  <ul class="socials">
    {#each links as link (`${link.platform}-${link.url}`)}
      <li>
        <a href={link.url} rel="nofollow noopener ugc" target="_blank">
          <Icon name={ICONS[link.platform.toLowerCase()] ?? "box-arrow-up-right"} />
          {link.label ?? link.platform}
        </a>
      </li>
    {/each}
  </ul>
{/if}