Dough Git

commit

Add a Discord component embed and PNG icon

commit
8b930c2dc587d2b3f5a81544b0b73f9ab25de826
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..4491b83
--- /dev/null
+++ b/src/lib/components/DiscordEmbed.svelte
@@ -0,0 +1,95 @@
+<!-- src/lib/components/DiscordEmbed.svelte
+     Copyright (c) 2026 Clove Nytrix Doughmination Twilight
+     Licensed under the DASL-1.2 Licence.
+     See LICENCE.md in the project root for full licence information.
+-->
+
+<script lang="ts">
+  import { page } from "$app/state";
+  import { mainSite, siteName } from "#lib";
+
+  let {
+    title,
+    description,
+  }: {
+    title: string;
+    description: 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(page.url.origin + 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: page.url.origin + "/favicon.png" },
+          },
+        },
+        { 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/routes/+page.svelte b/src/routes/+page.svelte
index dc75617..600921b 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -9,6 +9,7 @@
   import Flash from "#lib/components/Flash.svelte";
   import Pager from "#lib/components/Pager.svelte";
   import PasteRows from "#lib/components/PasteRows.svelte";
+  import DiscordEmbed from "#lib/components/DiscordEmbed.svelte";
 
   let { data } = $props();
 </script>
@@ -18,6 +19,11 @@
   <meta name="description" content="Public pastes on {siteName}." />
 </svelte:head>
 
+<DiscordEmbed
+  title="Recent pastes"
+  description="Public pastes on {siteName}."
+/>
+
 <div class="page">
   <div class="page-head">
     <p class="eyebrow">Pastebin</p>
diff --git a/src/routes/[slug]/+page.svelte b/src/routes/[slug]/+page.svelte
index 2f475a8..f96ea89 100644
--- a/src/routes/[slug]/+page.svelte
+++ b/src/routes/[slug]/+page.svelte
@@ -9,6 +9,7 @@
   import { bytes, date, relative } from "#lib/format.ts";
   import Flash from "#lib/components/Flash.svelte";
   import CodeView from "#lib/components/CodeView.svelte";
+  import DiscordEmbed from "#lib/components/DiscordEmbed.svelte";
 
   let { data } = $props();
 
@@ -53,6 +54,11 @@
   {/if}
 </svelte:head>
 
+<DiscordEmbed
+  {title}
+  description={`A paste by ${paste.authorUsername}.`}
+/>
+
 <div class="page">
   <Flash />
 
diff --git a/static/favicon.png b/static/favicon.png
new file mode 100644
index 0000000..f8a18f0
Binary files /dev/null and b/static/favicon.png differ