Dough Git

commit

Add a Discord component embed

commit
8b48abf27d0e6fb4f34a5105eca0d875e6aad261
author
Clove Twilight <[email protected]>
date
2026-10-30 00:44

diff --git a/src/lib/components/DiscordEmbed.svelte b/src/lib/components/DiscordEmbed.svelte
new file mode 100644
index 0000000..a4d3d08
--- /dev/null
+++ b/src/lib/components/DiscordEmbed.svelte
@@ -0,0 +1,97 @@
+<!-- src/lib/components/DiscordEmbed.svelte
+     Copyright (c) 2026 Clove Nytrix Doughmination Twilight
+     Licensed under the DASL-1.0 Licence.
+     See LICENCE.md in the project root for full licence information.
+-->
+
+<script lang="ts">
+  import { page } from "$app/state";
+  import { fallbackAvatar, mainSite, siteName, siteUrl } from "#lib";
+
+  let {
+    title,
+    description,
+    image = fallbackAvatar,
+  }: {
+    title: string;
+    description: string;
+    image?: string;
+  } = $props();
+
+  // Matches --accent in theme.css
+  const accentColour = 0xeb459e;
+
+  // Keeps the whole embed well under Discord's 3,000 byte cap
+  const maxDescription = 1000;
+
+  const pageUrl = $derived(siteUrl + page.url.pathname);
+
+  const shortDescription = $derived(
+    description.length > maxDescription
+      ? description.slice(0, maxDescription - 1) + "…"
+      : description,
+  );
+
+  // Discord component embed: one Container, Open Graph tags are the fallback
+  const componentEmbed = $derived({
+    component: {
+      type: 17,
+      accent_color: accentColour,
+      components: [
+        {
+          type: 9,
+          components: [
+            {
+              type: 10,
+              content: `## ${title}`,
+            },
+            {
+              type: 10,
+              content: shortDescription,
+            },
+          ],
+          accessory: {
+            type: 11,
+            media: { url: image },
+          },
+        },
+        { type: 14 },
+        {
+          type: 1,
+          components: [
+            {
+              type: 2,
+              style: 5,
+              label: "Open page",
+              url: pageUrl,
+            },
+            {
+              type: 2,
+              style: 5,
+              label: "doughmination.gay",
+              url: mainSite + "/",
+            },
+          ],
+        },
+        {
+          type: 10,
+          content: `-# ${siteName}`,
+        },
+      ],
+    },
+  });
+
+  // Escape '<' so the JSON can't close the script tag early
+  const toJson = (data: unknown) => JSON.stringify(data).replace(/</g, "\\u003c");
+
+  // Split closing tag so it doesn't end this script block
+  const closingTag = "</" + "script>";
+  const embedTag = $derived(
+    `<script id='discord:component-embed' type='application/json'>${toJson(componentEmbed)}${closingTag}`,
+  );
+</script>
+
+<svelte:head>
+  <!-- Built from page props, '<' escaped -->
+  {@html embedTag}
+</svelte:head>
diff --git a/src/lib/components/Home.svelte b/src/lib/components/Home.svelte
index e3980d7..cbb9cb9 100644
--- a/src/lib/components/Home.svelte
+++ b/src/lib/components/Home.svelte
@@ -12,6 +12,7 @@
   import { normalizeColor, readableOnDark } from "#lib/colour.ts";
   import { live } from "#lib/live.svelte.ts";
   import PrideSwatch from "#lib/components/PrideSwatch.svelte";
+  import DiscordEmbed from "#lib/components/DiscordEmbed.svelte";
 
   let {
     members: rawMembers,
@@ -133,6 +134,11 @@
   <meta name="twitter:card" content="summary" />
 </svelte:head>
 
+<DiscordEmbed
+  title="Doughmination System"
+  description="Real-time plural system tracker. View current fronters and members of the Doughmination System."
+/>
+
 <div class="page">
   {#if live.status === "reconnecting"}
     <p class="notice error" role="status">Live updates disconnected. Reconnecting…</p>
diff --git a/src/routes/[member_id]/+page.svelte b/src/routes/[member_id]/+page.svelte
index 39e058f..52a7d7a 100644
--- a/src/routes/[member_id]/+page.svelte
+++ b/src/routes/[member_id]/+page.svelte
@@ -8,6 +8,7 @@
   import { avatarFallback, fallbackAvatar, memberName, siteName, siteUrl } from "#lib";
   import { normalizeColor, readableOnDark } from "#lib/colour.ts";
   import PrideSwatch from "#lib/components/PrideSwatch.svelte";
+  import DiscordEmbed from "#lib/components/DiscordEmbed.svelte";
 
   let { data } = $props();
 
@@ -42,6 +43,12 @@
   <meta name="twitter:card" content="summary" />
 </svelte:head>
 
+<DiscordEmbed
+  title={name}
+  {description}
+  image={avatar}
+/>
+
 <div class="page narrow">
   <article class="panel member" style:--member-color={colour ?? "var(--accent)"}>
     <img class="member-avatar big" src={avatar} alt={name} onerror={avatarFallback} />
diff --git a/src/routes/relationships/+page.svelte b/src/routes/relationships/+page.svelte
index cc012ee..fd82710 100644
--- a/src/routes/relationships/+page.svelte
+++ b/src/routes/relationships/+page.svelte
@@ -8,6 +8,7 @@
   import { avatarFallback, fallbackAvatar, memberName } from "#lib";
   import PageHead from "#lib/components/PageHead.svelte";
   import RelationshipGraph from "#lib/components/RelationshipGraph.svelte";
+  import DiscordEmbed from "#lib/components/DiscordEmbed.svelte";
 
   let { data } = $props();
 
@@ -29,6 +30,11 @@
   <title>Relationship Map · Doughmination System</title>
 </svelte:head>
 
+<DiscordEmbed
+  title="Relationship Map"
+  description="Who is dating who across the system."
+/>
+
 <div class="page">
   <PageHead
     eyebrow="// system.relationships"