commit
Port to SvelteKit and the doughmination.gay look
Hono JSX views become SvelteKit routes on adapter-node, run with Bun. Strict CSP kept: paste colours are served from /<slug>/style.css instead of inline. IBM Plex Sans, Comic Code for code, iconsax icons. jpml-lang left npm, so the JPML parse check is now optional.
diff --git a/.dockerignore b/.dockerignore
index de15280..2261aa3 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -5,3 +5,5 @@ data
.github
*.md
!LICENCE.md
+build
+.svelte-kit
diff --git a/.env.example b/.env.example
index 3545901..5ea3d2b 100644
--- a/.env.example
+++ b/.env.example
@@ -12,6 +12,11 @@ SITE_NAME=Doughmination Paste
PORT=3030
HOST=0.0.0.0
+# SvelteKit works out each request's origin from the Host header and assumes
+# https. The reverse proxy must pass Host through. Serving plain http locally?
+# Set PROTOCOL_HEADER=x-forwarded-proto and have the proxy send it.
+# PROTOCOL_HEADER=x-forwarded-proto
+
# SQLite file. Its directory is created at start-up.
DATABASE_FILE=data/pastebin.db
diff --git a/.gitignore b/.gitignore
index c059056..ac566f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,8 @@ bun.lock
# output
out
dist
+build
+.svelte-kit
*.tgz
# code coverage
diff --git a/Dockerfile b/Dockerfile
index db82e26..257e94b 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,21 +3,28 @@
# Licensed under the DASL-1.2 Licence.
# See LICENCE.md in the project root for full licence information.
-FROM oven/bun:1.4-alpine AS deps
+FROM oven/bun:1.4-alpine AS build
WORKDIR /app
# bun.lock is gitignored in this repo, so tolerate it being absent.
COPY package.json bun.lock* ./
+RUN bun install
+COPY . .
+RUN bun run build
+
+FROM oven/bun:1.4-alpine AS deps
+WORKDIR /app
+COPY package.json bun.lock* ./
RUN bun install --production
FROM oven/bun:1.4-alpine
WORKDIR /app
ENV NODE_ENV=production
+# Room for the largest paste plus form overhead
+ENV BODY_SIZE_LIMIT=2M
COPY --from=deps /app/node_modules ./node_modules
-COPY package.json tsconfig.json ./
-COPY src ./src
-COPY public ./public
-COPY syntaxes ./syntaxes
+COPY --from=build /app/build ./build
+COPY package.json ./
# The database lives here; mount a volume over it to keep the pastes.
RUN mkdir -p /app/data && chown -R bun:bun /app/data
@@ -29,4 +36,4 @@ EXPOSE 3030
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s \
CMD bun -e "fetch('http://127.0.0.1:'+(process.env.PORT||3030)+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
-CMD ["bun", "src/index.ts"]
+CMD ["bun", "build/index.js"]
diff --git a/package.json b/package.json
index 4560c42..f04ad52 100644
--- a/package.json
+++ b/package.json
@@ -1,27 +1,36 @@
{
"name": "pastebin",
- "version": "1.0.0",
- "module": "src/index.ts",
+ "version": "2.0.0",
"type": "module",
"private": true,
"author": "Doughmination",
- "devDependencies": {
- "@types/bun": "latest"
+ "description": "Self-hosted pastebin for Doughmination: public to read, Doughmination SSO to write, with JPML syntax highlighting.",
+ "scripts": {
+ "dev": "bunx --bun vite dev",
+ "build": "bunx --bun vite build",
+ "start": "bun build/index.js",
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
+ "typecheck": "bun run check",
+ "sync:jpml": "bun run scripts/sync-jpml-grammar.ts"
+ },
+ "imports": {
+ "#lib": "./src/lib/index.ts",
+ "#lib/*": "./src/lib/*"
},
- "peerDependencies": {
- "typescript": "^7"
+ "devDependencies": {
+ "@sveltejs/adapter-node": "^6.0.0",
+ "@sveltejs/kit": "^3.1.0",
+ "@sveltejs/vite-plugin-svelte": "^7.3.1",
+ "@types/bun": "^1.4.4",
+ "svelte": "^5.57.3",
+ "svelte-check": "^4.7.7",
+ "typescript": "^6.0.3",
+ "vite": "^8.3.5"
},
"dependencies": {
- "hono": "^4.13.8",
+ "iconsax": "^0.1.1",
"jose": "^6.2.12",
- "jpml-lang": "^1.1.1",
- "shiki": "^4.4.3"
- },
- "description": "Self-hosted pastebin for Doughmination: public to read, Doughmination SSO to write, with JPML syntax highlighting.",
- "scripts": {
- "dev": "bun --watch src/index.ts",
- "start": "bun src/index.ts",
- "typecheck": "tsc --noEmit",
- "sync:jpml": "bun run scripts/sync-jpml-grammar.ts"
+ "shiki": "^4.4.3",
+ "simple-icons": "npm:@icons-pack/svelte-simple-icons@^7.2.0"
}
}
diff --git a/public/static/app.js b/public/static/app.js
deleted file mode 100644
index 37559ac..0000000
--- a/public/static/app.js
+++ /dev/null
@@ -1,164 +0,0 @@
-/* public/static/app.js
- * 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.
- */
-
-// Progressive enhancement only: every page here works with this file blocked.
-// Nothing below touches the network.
-
-(function () {
- "use strict";
-
- const page = document.body.dataset.page;
-
- if (page === "paste") setUpPaste();
- if (page === "composer") setUpComposer();
-
- // --- a paste --------------------------------------------------------------
-
- function setUpPaste() {
- const code = document.querySelector(".code");
- if (!code) return;
-
- const copyButton = document.querySelector("[data-copy-body]");
- if (copyButton && navigator.clipboard) {
- copyButton.addEventListener("click", async () => {
- const text = code.innerText.replace(/\n$/, "");
- try {
- await navigator.clipboard.writeText(text);
- flash(copyButton, "Copied");
- } catch {
- flash(copyButton, "Press Ctrl+C");
- }
- });
- } else if (copyButton) {
- copyButton.remove();
- }
-
- let anchorLine = null;
-
- // Clicking a line number selects that line and puts it in the address bar,
- // so the URL can be shared as a pointer at one line. Shift-click extends.
- code.addEventListener("click", (event) => {
- const line = event.target.closest(".line");
- if (!line || !line.id) return;
-
- // Only the number gutter reacts, so selecting code still works normally.
- const gutter = parseFloat(getComputedStyle(line).paddingLeft);
- if (!(event.offsetX >= 0 && event.offsetX < gutter && event.target === line)) return;
-
- const number = Number(line.id.slice(1));
- if (!Number.isFinite(number)) return;
-
- if (event.shiftKey && anchorLine !== null) {
- light(Math.min(anchorLine, number), Math.max(anchorLine, number));
- } else {
- anchorLine = number;
- light(number, number);
- }
- event.preventDefault();
- });
-
- function light(from, to) {
- for (const lit of code.querySelectorAll(".line.lit")) lit.classList.remove("lit");
- for (let n = from; n <= to; n++) {
- const line = document.getElementById("L" + n);
- if (line) line.classList.add("lit");
- }
- const hash = from === to ? "#L" + from : "#L" + from + "-L" + to;
- history.replaceState(null, "", hash);
- }
-
- // Restore a range that arrived in the URL, e.g. #L12-L20.
- const range = /^#L(\d+)(?:-L(\d+))?$/.exec(location.hash);
- if (range) {
- const from = Number(range[1]);
- const to = range[2] ? Number(range[2]) : from;
- anchorLine = from;
- if (to > from) light(from, to);
- const first = document.getElementById("L" + from);
- if (first) first.scrollIntoView({ block: "center" });
- }
-
- // Deleting a paste can't be undone, so ask once. The form still submits
- // normally for anyone without scripting.
- const deleteForm = document.querySelector("[data-confirm-delete]");
- if (deleteForm) {
- let armed = false;
- const button = deleteForm.querySelector("button");
- deleteForm.addEventListener("submit", (event) => {
- if (armed) return;
- event.preventDefault();
- armed = true;
- button.textContent = "Really delete?";
- setTimeout(() => {
- armed = false;
- button.textContent = "Delete";
- }, 4000);
- });
- }
- }
-
- function flash(button, text) {
- const original = button.textContent;
- button.textContent = text;
- setTimeout(() => {
- button.textContent = original;
- }, 1500);
- }
-
- // --- the composer ---------------------------------------------------------
-
- function setUpComposer() {
- const form = document.querySelector(".composer");
- if (!form) return;
-
- const textarea = form.querySelector("textarea[name=body]");
- const counter = form.querySelector("[data-counter]");
- const maxBytes = Number(form.dataset.maxBytes || 0);
-
- if (textarea && counter) {
- const encoder = new TextEncoder();
- const update = () => {
- const size = encoder.encode(textarea.value).length;
- counter.textContent = humanBytes(size);
- counter.classList.toggle("over", maxBytes > 0 && size > maxBytes);
- };
- textarea.addEventListener("input", update);
- update();
- }
-
- // Tab inserts an indent instead of leaving the field. Shift+Tab and Escape
- // still move focus, so the form stays keyboard-navigable.
- if (textarea) {
- textarea.addEventListener("keydown", (event) => {
- if (event.key !== "Tab" || event.shiftKey) return;
- event.preventDefault();
- const { selectionStart: start, selectionEnd: end, value } = textarea;
- textarea.value = value.slice(0, start) + " " + value.slice(end);
- textarea.selectionStart = textarea.selectionEnd = start + 2;
- });
- }
-
- // Picking a custom colour is what you meant by choosing "Custom".
- const customColour = form.querySelector("input[name=accent_custom]");
- if (customColour) {
- customColour.addEventListener("input", () => {
- const radio = form.querySelector("input[name=accent_choice][value=custom]");
- if (radio) radio.checked = true;
- });
- }
-
- // Ctrl/Cmd+Enter publishes, the way a commit message field would.
- form.addEventListener("keydown", (event) => {
- if ((event.ctrlKey || event.metaKey) && event.key === "Enter") form.requestSubmit();
- });
- }
-
- function humanBytes(count) {
- if (count < 1024) return count + " B";
- if (count < 1024 * 1024) return (count / 1024).toFixed(1) + " KB";
- return (count / (1024 * 1024)).toFixed(1) + " MB";
- }
-})();
diff --git a/public/static/style.css b/public/static/style.css
deleted file mode 100644
index 8921003..0000000
--- a/public/static/style.css
+++ /dev/null
@@ -1,654 +0,0 @@
-/* public/static/style.css
- * 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.
- */
-
-/* The palette is the auth server's, so signing in and coming back doesn't feel
- * like leaving the site. A paste may override --accent and the tints derived
- * from it on <body>; everything below reads through those variables so one
- * colour re-themes a page. */
-:root {
- --bg: #07050a;
- --surface: #100a10;
- --surface-2: #1a1016;
- --border: #34141c;
- --border-strong: #5c1c28;
- --text: #ece3e6;
- --muted: #9c848c;
- --accent: #9c1f34;
- --accent-strong: #c22a44;
- --accent-text: #fff2f2;
- --ok: #5f9e78;
- --ok-bg: rgba(95, 158, 120, 0.12);
- --danger: #ff4d5e;
- --danger-bg: rgba(255, 77, 94, 0.12);
- --focus: #e23a52;
- --focus-glow: rgba(226, 58, 82, 0.35);
- --accent-wash: rgba(156, 31, 52, 0.16);
- --accent-wash-soft: rgba(92, 28, 40, 0.12);
- --radius: 8px;
- --display-font: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
- --mono-font: ui-monospace, "Cascadia Code", Menlo, monospace;
- color-scheme: dark;
-}
-
-*,
-*::before,
-*::after {
- box-sizing: border-box;
-}
-
-html {
- -webkit-text-size-adjust: 100%;
-}
-
-body {
- margin: 0;
- min-height: 100vh;
- background:
- radial-gradient(ellipse 900px 480px at 50% -12%, var(--accent-wash), transparent 60%),
- radial-gradient(ellipse 700px 500px at 100% 110%, var(--accent-wash-soft), transparent 60%),
- var(--bg);
- background-attachment: fixed;
- color: var(--text);
- font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
- cursor: url("https://m.doughmination.gay/cursors/sandrone/Normal.png") 0 0, default;
-}
-
-a,
-button,
-.btn,
-select,
-summary,
-label[for],
-.swatch {
- cursor: url("https://m.doughmination.gay/cursors/sandrone/Link.png") 4 0, pointer;
-}
-
-input[type="text"],
-input[type="password"],
-input[type="email"],
-input[type="url"],
-textarea {
- cursor: url("https://m.doughmination.gay/cursors/sandrone/Text.png") 4 9, text;
-}
-
-button:disabled,
-input:disabled,
-select:disabled,
-textarea:disabled,
-[aria-disabled="true"] {
- cursor: url("https://m.doughmination.gay/cursors/sandrone/Unavailable.png") 0 0, not-allowed;
-}
-
-a {
- color: var(--accent-strong);
-}
-
-a:hover {
- color: var(--focus);
-}
-
-code {
- font-family: var(--mono-font);
- font-size: 0.9em;
- overflow-wrap: anywhere;
-}
-
-h1 {
- font-family: var(--display-font);
- font-size: 1.6rem;
- letter-spacing: 0.015em;
- margin: 0 0 0.75rem;
-}
-
-h2 {
- font-family: var(--display-font);
- font-size: 1.15rem;
- letter-spacing: 0.01em;
- margin: 0 0 0.5rem;
-}
-
-.muted {
- color: var(--muted);
-}
-
-.small {
- font-size: 0.875rem;
-}
-
-.grow {
- flex: 1;
- min-width: 0;
-}
-
-.hidden {
- display: none !important;
-}
-
-/* --- layout ------------------------------------------------------------------ */
-
-.topbar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 1rem;
- flex-wrap: wrap;
- padding: 0.75rem 16px;
- background: linear-gradient(180deg, var(--surface), #0b070a);
- border-bottom: 1px solid var(--border);
- box-shadow: 0 1px 0 var(--accent-wash);
-}
-
-.brand {
- color: var(--text);
- font-family: var(--display-font);
- font-size: 1.1rem;
- font-weight: 600;
- letter-spacing: 0.04em;
- text-decoration: none;
-}
-
-.topbar nav {
- display: flex;
- align-items: center;
- gap: 0.5rem;
- flex-wrap: wrap;
-}
-
-main {
- margin: 0 auto;
- padding: 1.5rem 16px 3rem;
-}
-
-main.wide {
- max-width: 960px;
-}
-
-main.narrow {
- max-width: 440px;
- padding-top: 3rem;
-}
-
-main.full {
- max-width: 1400px;
-}
-
-.card,
-.panel {
- position: relative;
- background: var(--surface);
- border: 1px solid var(--border);
- border-top: 1px solid var(--border-strong);
- border-radius: var(--radius);
- padding: 1.25rem;
- box-shadow: 0 16px 32px -20px rgba(0, 0, 0, 0.8);
-}
-
-.panel {
- margin: 1rem 0;
-}
-
-/* --- forms ------------------------------------------------------------------- */
-
-.stack {
- display: flex;
- flex-direction: column;
- gap: 0.85rem;
-}
-
-.grid2 {
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
- gap: 0.85rem;
-}
-
-.field {
- display: flex;
- flex-direction: column;
- gap: 0.3rem;
-}
-
-.field > span,
-.field > legend {
- font-weight: 550;
- font-size: 0.9rem;
-}
-
-input[type="text"],
-input[type="password"],
-input[type="email"],
-input[type="url"],
-select,
-textarea {
- width: 100%;
- min-width: 0;
- padding: 0.55rem 0.7rem;
- border: 1px solid var(--border);
- border-radius: 8px;
- background: var(--surface-2);
- color: var(--text);
- font: inherit;
-}
-
-textarea {
- resize: vertical;
- font-family: var(--mono-font);
- font-size: 0.875rem;
- line-height: 1.5;
- tab-size: 2;
-}
-
-input:disabled,
-input[readonly] {
- opacity: 0.7;
-}
-
-:focus-visible {
- outline: 2px solid var(--focus);
- outline-offset: 2px;
- box-shadow: 0 0 0 5px var(--focus-glow);
- border-radius: 4px;
-}
-
-fieldset {
- border: 1px solid var(--border);
- border-radius: 8px;
- padding: 0.75rem;
- margin: 0;
-}
-
-legend {
- padding: 0 0.3rem;
-}
-
-.check,
-.field-check {
- display: flex;
- align-items: flex-start;
- gap: 0.5rem;
- flex-direction: row;
-}
-
-.check input {
- margin-top: 0.3rem;
-}
-
-button,
-.btn {
- display: inline-flex;
- align-items: center;
- justify-content: center;
- gap: 0.4rem;
- padding: 0.55rem 1rem;
- border: 1px solid var(--border);
- border-radius: 8px;
- background: var(--surface-2);
- color: var(--text);
- font: inherit;
- font-weight: 550;
- text-decoration: none;
- transition: border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
-}
-
-button:hover:not(:disabled),
-.btn:hover:not([aria-disabled="true"]) {
- border-color: var(--accent-strong);
- color: var(--text);
-}
-
-button:disabled,
-.btn[aria-disabled="true"] {
- opacity: 0.55;
-}
-
-button.primary,
-.btn.primary {
- background: linear-gradient(180deg, var(--accent-strong), var(--accent) 85%);
- border-color: var(--border-strong);
- color: var(--accent-text);
-}
-
-button.primary:hover:not(:disabled),
-.btn.primary:hover {
- border-color: var(--focus);
- box-shadow: 0 0 0 3px var(--focus-glow);
- color: var(--accent-text);
-}
-
-button.danger,
-.btn.danger {
- color: var(--danger);
-}
-
-button.danger:hover:not(:disabled) {
- border-color: var(--danger);
-}
-
-button.small,
-.btn.small {
- padding: 0.3rem 0.65rem;
- font-size: 0.85rem;
-}
-
-form.inline {
- display: inline;
-}
-
-.buttons {
- display: flex;
- flex-wrap: wrap;
- gap: 0.5rem;
- align-items: center;
-}
-
-/* --- accent swatches ----------------------------------------------------------- */
-
-.swatches {
- display: flex;
- flex-wrap: wrap;
- gap: 0.5rem;
- margin-top: 0.4rem;
-}
-
-.swatch {
- display: inline-flex;
- align-items: center;
- gap: 0.45rem;
- padding: 0.3rem 0.7rem 0.3rem 0.45rem;
- border: 1px solid var(--border);
- border-radius: 999px;
- background: var(--surface-2);
- font-size: 0.85rem;
- color: var(--muted);
- transition: border-color 0.15s ease, color 0.15s ease;
-}
-
-.swatch:hover {
- border-color: var(--accent-strong);
- color: var(--text);
-}
-
-/* The radio itself is the accessible control; the dot is what you see. */
-.swatch input[type="radio"] {
- position: absolute;
- opacity: 0;
- width: 0;
- height: 0;
-}
-
-.swatch:has(input:checked) {
- border-color: var(--focus);
- color: var(--text);
- box-shadow: 0 0 0 2px var(--focus-glow);
-}
-
-.swatch:has(input:focus-visible) {
- outline: 2px solid var(--focus);
- outline-offset: 2px;
-}
-
-.swatch-dot {
- width: 1.1rem;
- height: 1.1rem;
- border-radius: 50%;
- border: 1px solid rgba(255, 255, 255, 0.22);
- background: var(--swatch, transparent);
- flex-shrink: 0;
-}
-
-.swatch-none .swatch-dot {
- background:
- linear-gradient(135deg, transparent 46%, var(--muted) 46%, var(--muted) 54%, transparent 54%),
- #1a1016;
-}
-
-.swatch-crimson { --swatch: #9c1f34; }
-.swatch-rose { --swatch: #c2456b; }
-.swatch-violet { --swatch: #7b4bc4; }
-.swatch-indigo { --swatch: #4257b2; }
-.swatch-teal { --swatch: #1f8a7a; }
-.swatch-moss { --swatch: #4f8a3d; }
-.swatch-amber { --swatch: #b07d1e; }
-.swatch-ember { --swatch: #c2562a; }
-
-.swatch-custom input[type="color"] {
- width: 1.6rem;
- height: 1.3rem;
- padding: 0;
- border: 1px solid var(--border);
- border-radius: 4px;
- background: none;
-}
-
-/* --- notices, badges, rows ------------------------------------------------------ */
-
-.notice {
- padding: 0.65rem 0.85rem;
- border: 1px solid var(--border);
- border-radius: 8px;
- background: var(--surface-2);
- margin: 0.75rem 0;
-}
-
-.notice.ok {
- border-color: var(--ok);
- background: var(--ok-bg);
-}
-
-.notice.error {
- border-color: var(--danger);
- background: var(--danger-bg);
-}
-
-.badge {
- display: inline-block;
- padding: 0.05rem 0.5rem;
- border: 1px solid var(--border);
- border-radius: 999px;
- font-size: 0.78rem;
- color: var(--muted);
- white-space: nowrap;
-}
-
-.badge.danger {
- color: var(--danger);
- border-color: var(--danger);
-}
-
-.rows {
- list-style: none;
- margin: 0.5rem 0 0.75rem;
- padding: 0;
-}
-
-.rows > li {
- display: flex;
- align-items: center;
- gap: 0.75rem;
- padding: 0.65rem 0;
- border-bottom: 1px solid var(--border);
-}
-
-.rows > li:last-child {
- border-bottom: 0;
-}
-
-.paste-link {
- font-family: var(--display-font);
- font-size: 1.05rem;
- text-decoration: none;
-}
-
-.paste-link:hover {
- text-decoration: underline;
-}
-
-.paste-meta {
- display: flex;
- flex-wrap: wrap;
- align-items: center;
- gap: 0.4rem;
- margin: 0.2rem 0 0;
-}
-
-.pager {
- display: flex;
- align-items: center;
- gap: 0.75rem;
- margin-top: 1rem;
-}
-
-/* --- a paste -------------------------------------------------------------------- */
-
-.paste {
- display: flex;
- flex-direction: column;
- gap: 0.75rem;
-}
-
-.paste-head {
- display: flex;
- align-items: flex-start;
- justify-content: space-between;
- gap: 1rem;
- flex-wrap: wrap;
-}
-
-.paste-head h1 {
- margin: 0;
- overflow-wrap: anywhere;
-}
-
-.paste-actions {
- flex-shrink: 0;
-}
-
-.jpml-note {
- margin: 0;
-}
-
-/* The code surface takes its background from the chosen highlight theme (Shiki
- * puts it on the <pre>), and the frame around it from the page accent. */
-.code {
- position: relative;
- border: 1px solid var(--border);
- border-top: 1px solid var(--border-strong);
- border-radius: var(--radius);
- overflow: hidden;
- box-shadow: 0 16px 32px -20px rgba(0, 0, 0, 0.8);
-}
-
-.code pre.shiki {
- margin: 0;
- padding: 1rem 0;
- overflow-x: auto;
- font-family: var(--mono-font);
- font-size: 0.875rem;
- line-height: 1.55;
- tab-size: 2;
-}
-
-.code pre.sh-plain {
- background: var(--surface);
- color: var(--text);
-}
-
-.code pre.shiki code {
- display: block;
- width: max-content;
- min-width: 100%;
- font-size: inherit;
- counter-reset: line;
-}
-
-.code .line {
- display: inline-block;
- width: 100%;
- padding: 0 1rem;
- scroll-margin-top: 4rem;
-}
-
-/* Line numbers are a counter rather than markup, so selecting the code and
- * copying it never picks them up. */
-.code.numbered pre.shiki code {
- counter-reset: line;
-}
-
-.code.numbered .line {
- padding-left: 4.2rem;
-}
-
-.code.numbered .line::before {
- counter-increment: line;
- content: counter(line);
- position: absolute;
- left: 0;
- width: 3.4rem;
- padding-right: 0.8rem;
- text-align: right;
- color: var(--muted);
- opacity: 0.55;
- user-select: none;
- -webkit-user-select: none;
-}
-
-.code.numbered .line {
- position: relative;
-}
-
-.code .line:target,
-.code .line.lit {
- background: var(--focus-glow);
- box-shadow: inset 3px 0 0 var(--focus);
-}
-
-.code .line:target::before,
-.code .line.lit::before {
- opacity: 1;
- color: var(--focus);
-}
-
-/* A light highlight theme brings its own pale background with it, so the
- * gutter and the frame move with it rather than staying dark against it. */
-.code.light {
- border-color: rgba(0, 0, 0, 0.18);
- color-scheme: light;
-}
-
-.code.light .line::before {
- color: #2a1a20;
- opacity: 0.4;
-}
-
-.code.light .line:target,
-.code.light .line.lit {
- background: rgba(0, 0, 0, 0.07);
-}
-
-::selection {
- background: var(--accent);
- color: var(--accent-text);
-}
-
-@media (max-width: 640px) {
- .paste-head {
- flex-direction: column;
- }
-
- .code.numbered .line {
- padding-left: 3.2rem;
- }
-
- .code.numbered .line::before {
- width: 2.6rem;
- padding-right: 0.6rem;
- }
-}
-
-@media (prefers-reduced-motion: reduce) {
- * {
- transition: none !important;
- }
-}
diff --git a/src/app.d.ts b/src/app.d.ts
new file mode 100644
index 0000000..c4da442
--- /dev/null
+++ b/src/app.d.ts
@@ -0,0 +1,36 @@
+/* src/app.d.ts
+ * 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.
+ */
+
+import type { CurrentUser, SessionInfo } from "#lib/server/env.ts";
+
+declare global {
+ namespace App {
+ interface Error {
+ message: string;
+ title?: string;
+ }
+
+ interface Locals {
+ session: SessionInfo | null;
+ user: CurrentUser | null;
+ }
+ }
+}
+
+// <iconsax-icon> is registered by `import "iconsax"` in src/hooks.client.ts
+declare module "svelte/elements" {
+ export interface SvelteHTMLElements {
+ "iconsax-icon": HTMLAttributes<HTMLElement> & {
+ name: string;
+ type?: "bold" | "broken" | "bulk" | "linear" | "outline" | "twotone";
+ size?: number | string;
+ color?: string;
+ pro?: boolean;
+ };
+ }
+}
+
+export {};
diff --git a/src/app.html b/src/app.html
new file mode 100644
index 0000000..0f75610
--- /dev/null
+++ b/src/app.html
@@ -0,0 +1,20 @@
+<!-- src/app.html
+ 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.
+-->
+
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="color-scheme" content="dark" />
+ <meta name="theme-color" content="#eb459e" />
+ <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
+ %sveltekit.head%
+ </head>
+ <body data-sveltekit-preload-data="hover">
+ <div class="app">%sveltekit.body%</div>
+ </body>
+</html>
diff --git a/src/auth/session.ts b/src/auth/session.ts
deleted file mode 100644
index 5c3092f..0000000
--- a/src/auth/session.ts
+++ /dev/null
@@ -1,77 +0,0 @@
-/* src/auth/session.ts
- * 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.
- */
-
-import { deleteCookie, getCookie, setCookie } from "hono/cookie";
-import { TTL, isSecure, now, type AppContext, type CurrentUser } from "../env";
-import { randomToken, sha256Hex, timingSafeEqualStr } from "../lib/crypto";
-import { createSession, deleteSession, getSession, getUser } from "../db";
-
-const COOKIE = "paste_session";
-
-/**
- * Only the hash of the cookie value is stored, so a copy of the database
- * doesn't hand anyone a working session.
- */
-export async function startSession(c: AppContext, userId: string): Promise<void> {
- const token = randomToken(32);
- const expiresAt = now() + TTL.session;
- createSession(await sha256Hex(token), userId, randomToken(16), expiresAt);
-
- setCookie(c, COOKIE, token, {
- httpOnly: true,
- secure: isSecure(),
- sameSite: "Lax",
- path: "/",
- maxAge: TTL.session,
- });
-}
-
-export async function endCurrentSession(c: AppContext): Promise<void> {
- const session = c.get("session");
- if (session) deleteSession(session.idHash);
- deleteCookie(c, COOKIE, { path: "/", secure: isSecure() });
-}
-
-/** Middleware: puts the signed-in user (or null) on the context for every route. */
-export async function loadSession(c: AppContext): Promise<void> {
- c.set("session", null);
- c.set("user", null);
-
- const token = getCookie(c, COOKIE);
- if (!token) return;
-
- const row = getSession(await sha256Hex(token));
- if (!row) {
- deleteCookie(c, COOKIE, { path: "/", secure: isSecure() });
- return;
- }
-
- const user = getUser(row.user_id);
- if (!user) {
- deleteSession(row.id_hash);
- return;
- }
-
- c.set("session", {
- idHash: row.id_hash,
- userId: row.user_id,
- csrf: row.csrf,
- expiresAt: row.expires_at,
- });
- c.set("user", {
- id: user.id,
- username: user.username,
- name: user.name,
- picture: user.picture,
- } satisfies CurrentUser);
-}
-
-/** Second CSRF layer, behind the Origin check in the request pipeline. */
-export function csrfOk(c: AppContext, submitted: string | undefined): boolean {
- const session = c.get("session");
- if (!session || !submitted) return false;
- return timingSafeEqualStr(submitted, session.csrf);
-}
diff --git a/src/hooks.client.ts b/src/hooks.client.ts
new file mode 100644
index 0000000..c4a3991
--- /dev/null
+++ b/src/hooks.client.ts
@@ -0,0 +1,8 @@
+/* src/hooks.client.ts
+ * 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.
+ */
+
+// Registers <iconsax-icon>. Client-only: the package extends HTMLElement, which doesn't exist during SSR
+import "iconsax";
diff --git a/src/hooks.server.ts b/src/hooks.server.ts
new file mode 100644
index 0000000..9849aaa
--- /dev/null
+++ b/src/hooks.server.ts
@@ -0,0 +1,72 @@
+/* src/hooks.server.ts
+ * 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.
+ */
+
+import type { Handle, HandleServerError, ServerInit } from "@sveltejs/kit/hooks";
+import { config, isSecure } from "#lib/server/env.ts";
+import { sweepExpired } from "#lib/server/db.ts";
+import { loadSession } from "#lib/server/session.ts";
+import { warmUp } from "#lib/server/highlight.ts";
+
+const ORIGIN = new URL(config.origin).origin;
+
+export const init: ServerInit = () => {
+ // Expired pastes are already invisible to every query; this is what actually
+ // reclaims the space, alongside spent sessions and abandoned sign-ins.
+ sweepExpired();
+ setInterval(sweepExpired, 60 * 60 * 1000).unref();
+
+ // Pull in the most-used grammars now so the first paste view isn't the
+ // request that pays for them.
+ warmUp().catch((err) => console.error("[highlight] warm-up failed:", err));
+
+ console.log(`${config.siteName} up (public origin ${config.origin})`);
+};
+
+function crossSite(request: Request): boolean {
+ const method = request.method;
+ if (method === "GET" || method === "HEAD" || method === "OPTIONS") return false;
+
+ const sentOrigin = request.headers.get("origin");
+ if (sentOrigin) return sentOrigin !== ORIGIN;
+
+ const site = request.headers.get("sec-fetch-site");
+ return Boolean(site && site !== "same-origin" && site !== "none");
+}
+
+export const handle: Handle = async ({ event, resolve }) => {
+ // CSRF, layer one: browsers label every cross-site request with Origin or
+ // Sec-Fetch-Site, so state-changing requests from elsewhere never reach a
+ // handler. Session-bound forms additionally carry a CSRF token.
+ if (crossSite(event.request)) {
+ return new Response("Cross-site request refused.", { status: 403 });
+ }
+
+ await loadSession(event);
+ const response = await resolve(event);
+
+ const headers = response.headers;
+ headers.set("X-Frame-Options", "DENY");
+ headers.set("X-Content-Type-Options", "nosniff");
+ headers.set("Referrer-Policy", "same-origin");
+ headers.set("Cross-Origin-Opener-Policy", "same-origin");
+ if (isSecure()) {
+ headers.set("Strict-Transport-Security", "max-age=63072000; includeSubDomains");
+ }
+ if (!headers.has("Cache-Control")) headers.set("Cache-Control", "no-store");
+
+ return response;
+};
+
+// App errors (thrown with error()) keep their own title and message; this only softens unknown ones
+export const handleError: HandleServerError = ({ kind, error, event }) => {
+ if (kind !== "unknown") return;
+
+ console.error("[error]", event.request.method, event.url.pathname, error);
+ return {
+ title: "Something went wrong",
+ message: "Something went wrong on our side. Please try again.",
+ };
+};
diff --git a/src/index.ts b/src/index.ts
deleted file mode 100644
index 85ddd4c..0000000
--- a/src/index.ts
+++ /dev/null
@@ -1,107 +0,0 @@
-/* src/index.ts
- * 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.
- */
-
-import { Hono } from "hono";
-import { serveStatic } from "hono/bun";
-import { config, isSecure, type AppEnv } from "./env";
-import { sweepExpired } from "./db";
-import { loadSession } from "./auth/session";
-import { randomToken } from "./lib/crypto";
-import { warmUp } from "./highlight";
-import { auth } from "./routes/auth";
-import { pastes } from "./routes/pastes";
-import { message } from "./views/layout";
-
-const app = new Hono<AppEnv>();
-
-const ORIGIN = new URL(config.origin).origin;
-
-app.use("*", async (c, next) => {
- // One nonce per response, for the single <style> block the layout emits.
- c.set("nonce", randomToken(16));
-
- // CSRF, layer one: browsers label every cross-site request with Origin or
- // Sec-Fetch-Site, so state-changing requests from elsewhere never reach a
- // handler. Session-bound forms additionally carry a CSRF token.
- const method = c.req.method;
- if (method !== "GET" && method !== "HEAD" && method !== "OPTIONS") {
- const sentOrigin = c.req.header("origin");
- const site = c.req.header("sec-fetch-site");
- if (sentOrigin ? sentOrigin !== ORIGIN : site && site !== "same-origin" && site !== "none") {
- return c.text("Cross-site request refused.", 403);
- }
- }
-
- await loadSession(c);
- await next();
-
- const h = c.res.headers;
- // Raw and download responses set their own, stricter policy.
- if (!h.has("Content-Security-Policy")) {
- h.set(
- "Content-Security-Policy",
- `default-src 'none'; script-src 'self'; style-src 'self' 'nonce-${c.get("nonce")}'; ` +
- "img-src 'self' https: data:; connect-src 'self'; form-action 'self'; " +
- "base-uri 'none'; frame-ancestors 'none'",
- );
- }
- h.set("X-Frame-Options", "DENY");
- h.set("X-Content-Type-Options", "nosniff");
- h.set("Referrer-Policy", "same-origin");
- h.set("Cross-Origin-Opener-Policy", "same-origin");
- if (isSecure()) h.set("Strict-Transport-Security", "max-age=63072000; includeSubDomains");
- if (!h.has("Cache-Control")) h.set("Cache-Control", "no-store");
-});
-
-app.use(
- "/static/*",
- serveStatic({
- root: "./public",
- onFound: (_path, c) => {
- c.header("Cache-Control", "public, max-age=3600");
- },
- }),
-);
-
-app.get("/favicon.ico", (c) => c.redirect("/static/favicon.svg", 301));
-
-app.get("/robots.txt", (c) => {
- c.header("Content-Type", "text/plain; charset=utf-8");
- c.header("Cache-Control", "public, max-age=3600");
- return c.body("User-agent: *\nDisallow: /new\nDisallow: /mine\nDisallow: /auth/\n");
-});
-
-app.get("/health", (c) => c.json({ ok: true }));
-
-app.route("/", auth);
-app.route("/", pastes);
-
-app.notFound((c) => message(c, "Not found", "There's nothing at that address.", 404));
-
-app.onError((err, c) => {
- console.error("[error]", c.req.method, new URL(c.req.url).pathname, err);
- return c.text("Something went wrong on our side. Please try again.", 500);
-});
-
-// Expired pastes are already invisible to every query; this is what actually
-// reclaims the space, alongside spent sessions and abandoned sign-ins.
-sweepExpired();
-setInterval(sweepExpired, 60 * 60 * 1000).unref();
-
-// Pull in the most-used grammars now so the first paste view isn't the request
-// that pays for them.
-warmUp().catch((err) => console.error("[highlight] warm-up failed:", err));
-
-console.log(`${config.siteName} listening on http://${config.host}:${config.port} (public origin ${config.origin})`);
-
-export default {
- port: config.port,
- hostname: config.host,
- // Generated slugs are short, but a title or body is not: allow a request
- // body comfortably past the configured paste limit for form overhead.
- maxRequestBodySize: config.maxBodyBytes + 1024 * 1024,
- fetch: app.fetch,
-};
diff --git a/src/lib/components/CodeView.svelte b/src/lib/components/CodeView.svelte
new file mode 100644
index 0000000..dfbaf7a
--- /dev/null
+++ b/src/lib/components/CodeView.svelte
@@ -0,0 +1,178 @@
+<!-- src/lib/components/CodeView.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 { onMount } from "svelte";
+
+ // `html` is Shiki's output, or the escaped plain fallback, from highlight.ts
+ let {
+ html,
+ numbered,
+ light,
+ }: {
+ html: string;
+ numbered: boolean;
+ light: boolean;
+ } = $props();
+
+ let box: HTMLDivElement;
+ let anchorLine: number | null = null;
+
+ export function text(): string {
+ return box.innerText.replace(/\n$/, "");
+ }
+
+ function lightUp(from: number, to: number) {
+ for (const lit of box.querySelectorAll(".line.lit")) lit.classList.remove("lit");
+ for (let line = from; line <= to; line++) {
+ document.getElementById(`L${line}`)?.classList.add("lit");
+ }
+ const hash = from === to ? `#L${from}` : `#L${from}-L${to}`;
+ history.replaceState(history.state, "", hash);
+ }
+
+ // Clicking a line number selects that line and puts it in the address bar. Shift-click extends
+ function onclick(event: MouseEvent) {
+ const target = event.target as HTMLElement;
+ const line = target.closest<HTMLElement>(".line");
+ if (!line?.id) return;
+
+ // Only the number gutter reacts, so selecting code still works normally
+ const gutter = parseFloat(getComputedStyle(line).paddingLeft);
+ if (!(event.offsetX >= 0 && event.offsetX < gutter && target === line)) return;
+
+ const number = Number(line.id.slice(1));
+ if (!Number.isFinite(number)) return;
+
+ if (event.shiftKey && anchorLine !== null) {
+ lightUp(Math.min(anchorLine, number), Math.max(anchorLine, number));
+ } else {
+ anchorLine = number;
+ lightUp(number, number);
+ }
+ event.preventDefault();
+ }
+
+ // Restore a range that arrived in the URL, e.g. #L12-L20
+ onMount(() => {
+ const range = /^#L(\d+)(?:-L(\d+))?$/.exec(location.hash);
+ if (!range) return;
+
+ const from = Number(range[1]);
+ const to = range[2] ? Number(range[2]) : from;
+ anchorLine = from;
+ if (to > from) lightUp(from, to);
+ document.getElementById(`L${from}`)?.scrollIntoView({ block: "center" });
+ });
+</script>
+
+<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
+<div bind:this={box} class="code" class:numbered class:light {onclick}>
+ {@html html}
+</div>
+
+<style>
+ /* The code surface takes its background from the chosen highlight theme (Shiki
+ puts it on the <pre>), and the frame around it from the page accent */
+ .code {
+ position: relative;
+ overflow: hidden;
+ border: 1px solid var(--line);
+ border-top-color: var(--accent-line);
+ border-radius: 1rem;
+ box-shadow:
+ 0 0 0 4px var(--accent-dim),
+ 0 16px 32px -20px rgb(0 0 0 / 80%);
+ }
+
+ .code :global(pre.shiki) {
+ margin: 0;
+ padding: 1rem 0;
+ overflow-x: auto;
+ font-family: var(--mono);
+ font-size: 0.875rem;
+ line-height: 1.55;
+ tab-size: 2;
+ }
+
+ .code :global(pre.sh-plain) {
+ background: rgb(0 0 0 / 30%);
+ color: var(--text);
+ }
+
+ .code :global(pre.shiki code) {
+ display: block;
+ width: max-content;
+ min-width: 100%;
+ font-size: inherit;
+ counter-reset: line;
+ }
+
+ .code :global(.line) {
+ display: inline-block;
+ position: relative;
+ width: 100%;
+ padding: 0 1rem;
+ scroll-margin-top: 4rem;
+ }
+
+ /* Line numbers are a counter rather than markup, so copying the code never picks them up */
+ .numbered :global(.line) {
+ padding-left: 4.2rem;
+ }
+
+ .numbered :global(.line::before) {
+ position: absolute;
+ left: 0;
+ width: 3.4rem;
+ padding-right: 0.8rem;
+ color: var(--muted);
+ text-align: right;
+ content: counter(line);
+ counter-increment: line;
+ opacity: 0.55;
+ user-select: none;
+ }
+
+ .code :global(.line:target),
+ .code :global(.line.lit) {
+ background: var(--accent-dim);
+ box-shadow: inset 3px 0 0 var(--accent);
+ }
+
+ .code :global(.line:target::before),
+ .code :global(.line.lit::before) {
+ color: var(--accent);
+ opacity: 1;
+ }
+
+ /* A light theme brings its own pale background, so the gutter and frame follow it */
+ .light {
+ border-color: rgb(0 0 0 / 18%);
+ color-scheme: light;
+ }
+
+ .light :global(.line::before) {
+ color: #2a1a20;
+ opacity: 0.4;
+ }
+
+ .light :global(.line:target),
+ .light :global(.line.lit) {
+ background: rgb(0 0 0 / 7%);
+ }
+
+ @media (max-width: 40rem) {
+ .numbered :global(.line) {
+ padding-left: 3.2rem;
+ }
+
+ .numbered :global(.line::before) {
+ width: 2.6rem;
+ padding-right: 0.6rem;
+ }
+ }
+</style>
diff --git a/src/lib/components/Composer.svelte b/src/lib/components/Composer.svelte
new file mode 100644
index 0000000..3d55795
--- /dev/null
+++ b/src/lib/components/Composer.svelte
@@ -0,0 +1,320 @@
+<!-- src/lib/components/Composer.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 { bytes } from "#lib/format.ts";
+ import type { ComposerOptions, ComposerValues } from "#lib/server/compose.ts";
+
+ let {
+ values,
+ options,
+ csrf,
+ error = null,
+ editing,
+ }: {
+ values: ComposerValues;
+ options: ComposerOptions;
+ csrf: string;
+ error?: string | null;
+ // Present when editing: the slug is already spent and can't move
+ editing?: string;
+ } = $props();
+
+ // Seeded once from the server's values; the form owns them after that
+ // svelte-ignore state_referenced_locally
+ let body = $state(values.body);
+ // svelte-ignore state_referenced_locally
+ let accentChoice = $state(values.accentChoice);
+
+ let form: HTMLFormElement;
+
+ const encoder = new TextEncoder();
+ const size = $derived(encoder.encode(body).length);
+ const over = $derived(size > options.maxBytes);
+
+ // Tab inserts an indent instead of leaving the field. Shift+Tab and Escape still move focus
+ function indent(event: KeyboardEvent) {
+ if (event.key !== "Tab" || event.shiftKey) return;
+ event.preventDefault();
+
+ const textarea = event.currentTarget as HTMLTextAreaElement;
+ const { selectionStart: start, selectionEnd: end } = textarea;
+ body = body.slice(0, start) + " " + body.slice(end);
+
+ queueMicrotask(() => {
+ textarea.selectionStart = start + 2;
+ textarea.selectionEnd = start + 2;
+ });
+ }
+
+ // Ctrl/Cmd+Enter publishes, the way a commit message field would
+ function submitShortcut(event: KeyboardEvent) {
+ if ((event.ctrlKey || event.metaKey) && event.key === "Enter") form.requestSubmit();
+ }
+</script>
+
+<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
+<form
+ bind:this={form}
+ method="post"
+ action={editing ? `/${editing}/edit` : "/new"}
+ class="stack"
+ onkeydown={submitShortcut}
+>
+ <input type="hidden" name="_csrf" value={csrf} />
+
+ {#if error}
+ <p class="notice error" role="alert">{error}</p>
+ {/if}
+
+ <div class="grid2">
+ <label class="field">
+ <span>Title</span>
+ <!-- svelte-ignore a11y_autofocus -->
+ <input type="text" name="title" value={values.title} maxlength="200" placeholder="Optional" autofocus />
+ </label>
+
+ <label class="field">
+ <span>Slug</span>
+ {#if editing}
+ <input type="text" value={editing} readonly disabled />
+ {:else}
+ <input
+ type="text"
+ name="slug"
+ value={values.slug}
+ maxlength="64"
+ placeholder="Optional — a short one is generated"
+ pattern="[A-Za-z0-9_\-]{'{'}3,64{'}'}"
+ autocapitalize="off"
+ autocorrect="off"
+ spellcheck="false"
+ />
+ {/if}
+ <small class="muted">
+ {editing ? "A paste keeps its address for good." : "Becomes the address: /your-slug"}
+ </small>
+ </label>
+ </div>
+
+ <label class="field">
+ <span>Content</span>
+ <textarea
+ name="body"
+ rows="22"
+ required
+ spellcheck="false"
+ autocapitalize="off"
+ placeholder="Paste away."
+ bind:value={body}
+ onkeydown={indent}
+ ></textarea>
+ <small class="muted">
+ <span class:over>{bytes(size)}</span> of {bytes(options.maxBytes)}
+ </small>
+ </label>
+
+ <div class="grid2">
+ <label class="field">
+ <span>Language</span>
+ <select name="language" value={values.language}>
+ {#each options.languages as language (language.id)}
+ <option value={language.id}>{language.label}</option>
+ {/each}
+ </select>
+ </label>
+
+ <label class="field">
+ <span>Highlight theme</span>
+ <select name="theme" value={values.theme}>
+ {#each options.themes as theme (theme.id)}
+ <option value={theme.id}>{theme.label}</option>
+ {/each}
+ </select>
+ </label>
+ </div>
+
+ <fieldset class="field">
+ <legend>Accent colour</legend>
+ <p class="muted small hint">Re-tints this paste's page. Everything else keeps the site's own colours.</p>
+
+ <div class="swatches">
+ <label class="swatch" title="Site default">
+ <input type="radio" name="accent_choice" value="none" bind:group={accentChoice} />
+ <span class="swatch-dot swatch-none" aria-hidden="true"></span>
+ <span>Default</span>
+ </label>
+
+ {#each options.accents as preset (preset.id)}
+ <label class="swatch" title={preset.label}>
+ <input type="radio" name="accent_choice" value={preset.id} bind:group={accentChoice} />
+ <span class="swatch-dot swatch-{preset.id}" aria-hidden="true"></span>
+ <span>{preset.label}</span>
+ </label>
+ {/each}
+
+ <label class="swatch" title="Custom colour">
+ <input type="radio" name="accent_choice" value="custom" bind:group={accentChoice} />
+ <!-- Picking a custom colour is what you meant by choosing "Custom" -->
+ <input
+ type="color"
+ name="accent_custom"
+ value={values.accentCustom}
+ aria-label="Custom accent colour"
+ oninput={() => (accentChoice = "custom")}
+ />
+ <span>Custom</span>
+ </label>
+ </div>
+ </fieldset>
+
+ <div class="grid2">
+ <label class="field">
+ <span>Expires</span>
+ <select name="expiry" value={values.expiry}>
+ {#each options.expiries as option (option.id)}
+ <option value={option.id}>{option.label}</option>
+ {/each}
+ </select>
+ </label>
+
+ <label class="check unlisted">
+ <input type="checkbox" name="unlisted" value="1" checked={values.unlisted} />
+ <span>
+ Unlisted
+ <small class="muted"> — reachable by link, kept off the front page.</small>
+ </span>
+ </label>
+ </div>
+
+ <div class="buttons">
+ <button type="submit" class="primary">
+ <iconsax-icon name={editing ? "tick-circle" : "send-2"} type="bulk" size="18"></iconsax-icon>
+ {editing ? "Save changes" : "Publish paste"}
+ </button>
+ <a class="btn" href={editing ? `/${editing}` : "/"}>Cancel</a>
+ </div>
+</form>
+
+<style>
+ .over {
+ color: var(--bad);
+ font-weight: 600;
+ }
+
+ .hint {
+ margin: 0;
+ }
+
+ .unlisted {
+ align-self: end;
+ padding-bottom: 0.5rem;
+ }
+
+ .swatches {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.5rem;
+ margin-top: 0.4rem;
+ }
+
+ .swatch {
+ display: inline-flex;
+ gap: 0.45rem;
+ align-items: center;
+ padding: 0.3rem 0.75rem 0.3rem 0.45rem;
+ border: 1px solid var(--line);
+ border-radius: 999px;
+ background: var(--raised);
+ color: var(--muted);
+ font-size: 0.85rem;
+ cursor: pointer;
+ transition:
+ border-color 0.15s ease,
+ color 0.15s ease;
+ }
+
+ .swatch:hover {
+ border-color: var(--accent-line);
+ color: var(--text);
+ }
+
+ /* The radio itself is the accessible control; the dot is what you see */
+ .swatch input[type="radio"] {
+ position: absolute;
+ width: 0;
+ height: 0;
+ opacity: 0;
+ }
+
+ .swatch:has(input[type="radio"]:checked) {
+ border-color: var(--accent);
+ color: var(--text);
+ box-shadow: 0 0 0 4px var(--accent-dim);
+ }
+
+ .swatch:has(input:focus-visible) {
+ outline: 2px solid var(--accent);
+ outline-offset: 2px;
+ }
+
+ .swatch-dot {
+ flex-shrink: 0;
+ width: 1.1rem;
+ height: 1.1rem;
+ border: 1px solid rgb(255 255 255 / 22%);
+ border-radius: 50%;
+ background: var(--swatch, transparent);
+ }
+
+ .swatch-none {
+ background:
+ linear-gradient(135deg, transparent 46%, var(--muted) 46%, var(--muted) 54%, transparent 54%),
+ var(--bg);
+ }
+
+ /* Classes rather than inline styles: the CSP allows no style attributes */
+ .swatch-crimson {
+ --swatch: #9c1f34;
+ }
+
+ .swatch-rose {
+ --swatch: #c2456b;
+ }
+
+ .swatch-violet {
+ --swatch: #7b4bc4;
+ }
+
+ .swatch-indigo {
+ --swatch: #4257b2;
+ }
+
+ .swatch-teal {
+ --swatch: #1f8a7a;
+ }
+
+ .swatch-moss {
+ --swatch: #4f8a3d;
+ }
+
+ .swatch-amber {
+ --swatch: #b07d1e;
+ }
+
+ .swatch-ember {
+ --swatch: #c2562a;
+ }
+
+ .swatch input[type="color"] {
+ width: 1.6rem;
+ height: 1.3rem;
+ padding: 0;
+ border: 1px solid var(--line);
+ border-radius: 4px;
+ background: none;
+ }
+</style>
diff --git a/src/lib/components/Flash.svelte b/src/lib/components/Flash.svelte
new file mode 100644
index 0000000..0b1410e
--- /dev/null
+++ b/src/lib/components/Flash.svelte
@@ -0,0 +1,16 @@
+<!-- src/lib/components/Flash.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 { flashText } from "#lib/format.ts";
+
+ const text = $derived(flashText(page.url.searchParams.get("m")));
+</script>
+
+{#if text}
+ <p class="notice ok" role="status">{text}</p>
+{/if}
diff --git a/src/lib/components/Footer.svelte b/src/lib/components/Footer.svelte
new file mode 100644
index 0000000..d5da157
--- /dev/null
+++ b/src/lib/components/Footer.svelte
@@ -0,0 +1,26 @@
+<!-- src/lib/components/Footer.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 "#lib/styles/footer.css";
+ import { mainSite, siteName } from "#lib";
+</script>
+
+<footer>
+ <p class="footer-line">
+ <span class="footer-brand">
+ <img src="/favicon.svg" alt="" width="20" height="20" />
+ {siteName}
+ </span>
+
+ <span>
+ part of <a href={mainSite}>doughmination.gay</a>
+ <iconsax-icon name="heart" type="bulk" size="16" class="beat"></iconsax-icon>
+ </span>
+
+ <span>Clove Twilight © 2026</span>
+ </p>
+</footer>
diff --git a/src/lib/components/Header.svelte b/src/lib/components/Header.svelte
new file mode 100644
index 0000000..7ed796e
--- /dev/null
+++ b/src/lib/components/Header.svelte
@@ -0,0 +1,70 @@
+<!-- src/lib/components/Header.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 "#lib/styles/header.css";
+ import { page } from "$app/state";
+ import { siteName } from "#lib";
+ let {
+ user,
+ csrf,
+ }: {
+ user: { username: string } | null;
+ csrf: string;
+ } = $props();
+
+ const returnTo = $derived(encodeURIComponent(page.url.pathname + page.url.search));
+</script>
+
+<!-- Fixed-height page backdrop, so every page gets the same amount of background -->
+<div class="backdrop" aria-hidden="true"></div>
+
+<header>
+ <a class="brand" href="/">
+ <img src="/favicon.svg" alt="" width="32" height="32" />
+ <span>{siteName}</span>
+ </a>
+
+ <nav>
+ <a href="/">
+ <iconsax-icon name="document-text" type="bulk" size="24" class="nav-icon"></iconsax-icon>Recent
+ </a>
+
+ {#if user}
+ <a href="/mine">
+ <iconsax-icon name="folder-2" type="bulk" size="24" class="nav-icon"></iconsax-icon>Mine
+ </a>
+ <a href="/new">
+ <iconsax-icon name="add-circle" type="bulk" size="24" class="nav-icon"></iconsax-icon>New paste
+ </a>
+ <form method="post" action="/auth/logout" class="inline">
+ <input type="hidden" name="_csrf" value={csrf} />
+ <button type="submit" class="nav-button" title="Signed in as {user.username}">
+ <iconsax-icon name="logout-01" type="bulk" size="24" class="nav-icon"></iconsax-icon>Sign out
+ </button>
+ </form>
+ {:else}
+ <a href="/auth/login?return_to={returnTo}">
+ <iconsax-icon name="login-01" type="bulk" size="24" class="nav-icon"></iconsax-icon>Sign in
+ </a>
+ {/if}
+ </nav>
+</header>
+
+<style>
+ /* A form button that reads as one of the header's links */
+ .nav-button {
+ padding: 0;
+ border: 0;
+ background: none;
+ color: var(--muted);
+ font-size: inherit;
+ }
+
+ .nav-button:hover:not(:disabled) {
+ color: var(--text);
+ }
+</style>
diff --git a/src/lib/components/Pager.svelte b/src/lib/components/Pager.svelte
new file mode 100644
index 0000000..51170ea
--- /dev/null
+++ b/src/lib/components/Pager.svelte
@@ -0,0 +1,44 @@
+<!-- src/lib/components/Pager.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">
+ // Links to the next and previous page of a listing, when there is one
+ let {
+ path,
+ page,
+ total,
+ perPage,
+ }: {
+ path: string;
+ page: number;
+ total: number;
+ perPage: number;
+ } = $props();
+
+ const pages = $derived(Math.max(1, Math.ceil(total / perPage)));
+
+ function link(target: number): string {
+ return target <= 1 ? path : `${path}?page=${target}`;
+ }
+</script>
+
+{#if pages > 1}
+ <nav class="pager">
+ {#if page > 1}
+ <a class="btn small" href={link(page - 1)}>Newer</a>
+ {:else}
+ <span class="btn small" aria-disabled="true">Newer</span>
+ {/if}
+
+ <span class="muted small">Page {page} of {pages}</span>
+
+ {#if page < pages}
+ <a class="btn small" href={link(page + 1)}>Older</a>
+ {:else}
+ <span class="btn small" aria-disabled="true">Older</span>
+ {/if}
+ </nav>
+{/if}
diff --git a/src/lib/components/PasteRows.svelte b/src/lib/components/PasteRows.svelte
new file mode 100644
index 0000000..6d40892
--- /dev/null
+++ b/src/lib/components/PasteRows.svelte
@@ -0,0 +1,72 @@
+<!-- src/lib/components/PasteRows.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 { date, relative } from "#lib/format.ts";
+
+ type Row = {
+ slug: string;
+ title: string | null;
+ languageLabel: string;
+ author: string;
+ created_at: number;
+ unlisted: number;
+ expires_at: number | null;
+ };
+
+ let {
+ pastes,
+ showAuthor = true,
+ empty,
+ }: {
+ pastes: Row[];
+ showAuthor?: boolean;
+ empty: string;
+ } = $props();
+</script>
+
+{#if pastes.length === 0}
+ <p class="muted">{empty}</p>
+{:else}
+ <ul class="rows">
+ {#each pastes as paste (paste.slug)}
+ <li>
+ <div class="grow">
+ <a class="paste-link" href="/{paste.slug}">{paste.title ?? paste.slug}</a>
+ <p class="muted small meta">
+ <code>/{paste.slug}</code>
+ <span aria-hidden="true">·</span>
+ <span>{paste.languageLabel}</span>
+ {#if showAuthor}
+ <span aria-hidden="true">·</span>
+ <span>{paste.author}</span>
+ {/if}
+ <span aria-hidden="true">·</span>
+ <span title={date(paste.created_at)}>{relative(paste.created_at)}</span>
+ {#if paste.unlisted === 1}
+ <span class="badge">unlisted</span>
+ {/if}
+ {#if paste.expires_at !== null}
+ <span class="badge danger">expiring</span>
+ {/if}
+ </p>
+ </div>
+ </li>
+ {/each}
+ </ul>
+{/if}
+
+<style>
+ .paste-link {
+ font-size: 1.05rem;
+ font-weight: 600;
+ text-decoration: none;
+ }
+
+ .paste-link:hover {
+ color: var(--accent);
+ }
+</style>
diff --git a/src/lib/fonts/IBMPlexSans-Bold.woff2 b/src/lib/fonts/IBMPlexSans-Bold.woff2
new file mode 100644
index 0000000..486c376
Binary files /dev/null and b/src/lib/fonts/IBMPlexSans-Bold.woff2 differ
diff --git a/src/lib/fonts/IBMPlexSans-Medium.woff2 b/src/lib/fonts/IBMPlexSans-Medium.woff2
new file mode 100644
index 0000000..ce72c05
Binary files /dev/null and b/src/lib/fonts/IBMPlexSans-Medium.woff2 differ
diff --git a/src/lib/fonts/IBMPlexSans-Regular.woff2 b/src/lib/fonts/IBMPlexSans-Regular.woff2
new file mode 100644
index 0000000..136597e
Binary files /dev/null and b/src/lib/fonts/IBMPlexSans-Regular.woff2 differ
diff --git a/src/lib/fonts/IBMPlexSans-SemiBold.woff2 b/src/lib/fonts/IBMPlexSans-SemiBold.woff2
new file mode 100644
index 0000000..78cbe9a
Binary files /dev/null and b/src/lib/fonts/IBMPlexSans-SemiBold.woff2 differ
diff --git a/src/lib/format.ts b/src/lib/format.ts
new file mode 100644
index 0000000..6c80115
--- /dev/null
+++ b/src/lib/format.ts
@@ -0,0 +1,57 @@
+/* src/lib/format.ts
+ * 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.
+ */
+
+export function date(ts: number | null | undefined): string {
+ if (!ts) return "never";
+ return new Date(ts * 1000).toISOString().slice(0, 16).replace("T", " ") + " UTC";
+}
+
+export function relative(ts: number | null | undefined): string {
+ if (!ts) return "never";
+ const diff = Math.floor(Date.now() / 1000) - ts;
+ const future = diff < 0;
+ const abs = Math.abs(diff);
+
+ let count: number;
+ let word: string;
+ if (abs < 60) {
+ count = abs;
+ word = "second";
+ } else if (abs < 3600) {
+ count = Math.floor(abs / 60);
+ word = "minute";
+ } else if (abs < 86400) {
+ count = Math.floor(abs / 3600);
+ word = "hour";
+ } else {
+ count = Math.floor(abs / 86400);
+ word = "day";
+ }
+
+ const text = `${count} ${word}${count === 1 ? "" : "s"}`;
+ return future ? `in ${text}` : `${text} ago`;
+}
+
+export function bytes(count: number): string {
+ if (count < 1024) return `${count} B`;
+ if (count < 1024 * 1024) return `${(count / 1024).toFixed(count < 10240 ? 1 : 0)} KB`;
+ return `${(count / (1024 * 1024)).toFixed(1)} MB`;
+}
+
+// Flash messages travel as a fixed code in `?m=`, never as free text, so a
+// crafted link can't put words in this site's mouth.
+const FLASH: Record<string, string> = {
+ "signed-in": "You're signed in.",
+ "signed-out": "You're signed out.",
+ "paste-created": "Paste published.",
+ "paste-updated": "Paste updated.",
+ "paste-deleted": "Paste deleted.",
+ "sign-in-needed": "Sign in to publish a paste.",
+};
+
+export function flashText(code: string | null): string | undefined {
+ return code ? FLASH[code] : undefined;
+}
diff --git a/src/lib/http.ts b/src/lib/http.ts
deleted file mode 100644
index 1711883..0000000
--- a/src/lib/http.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-/* src/lib/http.ts
- * 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.
- */
-
-import type { AppContext } from "../env";
-
-/** Parsed form body with every value coerced to a string (files dropped). */
-export async function form(c: AppContext): Promise<Record<string, string>> {
- const body = await c.req.parseBody({ all: true });
- const out: Record<string, string> = {};
- for (const [key, value] of Object.entries(body)) {
- const first = Array.isArray(value) ? value[0] : value;
- if (typeof first === "string") out[key] = first;
- }
- return out;
-}
-
-/** Only same-site paths: "/x" yes, "//host", "/\host" and absolute URLs no. */
-export function safeReturn(raw: unknown, fallback = "/"): string {
- if (typeof raw !== "string" || !raw.startsWith("/")) return fallback;
- if (raw.startsWith("//") || raw.startsWith("/\\")) return fallback;
- if (/[\x00-\x20]/.test(raw)) return fallback;
- return raw.length > 2048 ? fallback : raw;
-}
-
-export function clientIp(c: AppContext): string {
- const forwarded = c.req.header("x-forwarded-for");
- if (forwarded) return forwarded.split(",")[0]!.trim();
- return c.req.header("cf-connecting-ip") ?? "unknown";
-}
diff --git a/src/lib/index.ts b/src/lib/index.ts
new file mode 100644
index 0000000..2bd5ea4
--- /dev/null
+++ b/src/lib/index.ts
@@ -0,0 +1,9 @@
+/* src/lib/index.ts
+ * 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.
+ */
+
+export const siteName = "Doughmination Paste";
+
+export const mainSite = "https://doughmination.gay";
diff --git a/src/lib/colour.ts b/src/lib/server/colour.ts
similarity index 87%
rename from src/lib/colour.ts
rename to src/lib/server/colour.ts
index f4db235..20df977 100644
--- a/src/lib/colour.ts
+++ b/src/lib/server/colour.ts
@@ -1,4 +1,4 @@
-/* src/lib/colour.ts
+/* src/lib/server/colour.ts
* 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.
@@ -17,7 +17,7 @@ export interface AccentPreset {
hex: string;
}
-/** The site's own crimson first; the rest are picked to stay legible on #07050a. */
+/** Picked to stay legible on the site background, #0b0a0d. */
export const ACCENT_PRESETS: AccentPreset[] = [
{ id: "crimson", label: "Crimson", hex: "#9c1f34" },
{ id: "rose", label: "Rose", hex: "#c2456b" },
@@ -122,7 +122,7 @@ function rgba(hex: string, alpha: number): string {
/** Mixes `hex` toward the page background, for borders that read as tinted, not coloured. */
function towardBackground(hex: string, amount: number): string {
const [r, g, b] = toRgb(hex);
- const [br, bg, bb] = toRgb("#07050a");
+ const [br, bg, bb] = toRgb("#0b0a0d");
const mix = (a: number, back: number) => Math.round(back + (a - back) * amount);
const channel = (v: number) => v.toString(16).padStart(2, "0");
return `#${channel(mix(r, br))}${channel(mix(g, bg))}${channel(mix(b, bb))}`;
@@ -130,7 +130,7 @@ function towardBackground(hex: string, amount: number): string {
/**
* The CSS custom properties that re-tint a page. Names match the ones
- * `style.css` defines on `:root`, so setting them on an element overrides the
+ * `theme.css` defines on `:root`, so setting them on an element overrides the
* site default for that subtree and nothing else.
*/
export function accentVars(hex: string): string {
@@ -141,17 +141,12 @@ export function accentVars(hex: string): string {
const base = toHex({ h: hsl.h, s: clamp(hsl.s, 0.25), l: clamp(hsl.l, 0.24, 0.62) });
const baseHsl = toHsl(base);
- const strong = shift(baseHsl, 0.08, 0.04);
- const focus = shift(baseHsl, 0.16, 0.06);
+ const bright = shift(baseHsl, 0.16, 0.06);
return [
- `--accent:${base}`,
- `--accent-strong:${strong}`,
- `--focus:${focus}`,
- `--focus-glow:${rgba(focus, 0.35)}`,
- `--border:${towardBackground(base, 0.34)}`,
- `--border-strong:${towardBackground(base, 0.62)}`,
- `--accent-wash:${rgba(base, 0.16)}`,
- `--accent-wash-soft:${rgba(base, 0.1)}`,
+ `--accent:${bright}`,
+ `--accent-dim:${rgba(bright, 0.14)}`,
+ `--accent-line:${rgba(bright, 0.4)}`,
+ `--line:${towardBackground(base, 0.3)}`,
].join(";");
}
diff --git a/src/lib/server/compose.ts b/src/lib/server/compose.ts
new file mode 100644
index 0000000..c0d59cc
--- /dev/null
+++ b/src/lib/server/compose.ts
@@ -0,0 +1,204 @@
+/* src/lib/server/compose.ts
+ * 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.
+ */
+
+import { error, type RequestEvent } from "@sveltejs/kit";
+import { config } from "./env.ts";
+import { getPaste, slugTaken, type PasteWithAuthor } from "./db.ts";
+import { randomSlug } from "./crypto.ts";
+import { ACCENT_PRESETS, normaliseHex } from "./colour.ts";
+import {
+ EXPIRY_OPTIONS,
+ expiresAtFrom,
+ expiryIdFrom,
+ expiryProblem,
+ normaliseBody,
+ normaliseSlug,
+} from "./validate.ts";
+import {
+ DEFAULT_THEME,
+ LANGUAGES,
+ THEMES,
+ isLanguage,
+ isTheme,
+} from "./highlight.ts";
+
+/** Pastes one account may publish per hour, so a stuck script can't fill the disk. */
+export const HOURLY_LIMIT = 60;
+
+export interface ComposerValues {
+ title: string;
+ slug: string;
+ body: string;
+ language: string;
+ theme: string;
+ accentChoice: string;
+ accentCustom: string;
+ expiry: string;
+ unlisted: boolean;
+}
+
+/** Everything the composer's selects and swatches offer */
+export function composerOptions() {
+ return {
+ languages: LANGUAGES,
+ themes: THEMES,
+ expiries: EXPIRY_OPTIONS,
+ accents: ACCENT_PRESETS,
+ maxBytes: config.maxBodyBytes,
+ };
+}
+
+export type ComposerOptions = ReturnType<typeof composerOptions>;
+
+export function blankValues(): ComposerValues {
+ return {
+ title: "",
+ slug: "",
+ body: "",
+ language: "text",
+ theme: DEFAULT_THEME,
+ accentChoice: "none",
+ accentCustom: "#eb459e",
+ expiry: "never",
+ unlisted: false,
+ };
+}
+
+/** Works out which accent control an existing paste's stored colour came from. */
+export function valuesFrom(paste: PasteWithAuthor): ComposerValues {
+ const preset = paste.accent
+ ? ACCENT_PRESETS.find((p) => p.hex === paste.accent)
+ : undefined;
+
+ return {
+ title: paste.title ?? "",
+ slug: paste.slug,
+ body: paste.body,
+ language: paste.language,
+ theme: paste.theme,
+ accentChoice: paste.accent === null ? "none" : (preset?.id ?? "custom"),
+ accentCustom: paste.accent ?? "#eb459e",
+ expiry: expiryIdFrom(paste.expires_at),
+ unlisted: paste.unlisted === 1,
+ };
+}
+
+export interface Parsed {
+ values: ComposerValues;
+ error: string | null;
+ /** Filled in only when `error` is null. */
+ accent: string | null;
+ expiresAt: number | null;
+}
+
+function field(form: FormData, name: string): string | undefined {
+ const value = form.get(name);
+ return typeof value === "string" ? value : undefined;
+}
+
+/**
+ * Reads the composer form back into validated fields. Everything the user
+ * typed survives on the returned `values` so a rejected submission can be
+ * re-rendered without losing the paste.
+ */
+export function parseComposer(form: FormData): Parsed {
+ const accentChoice = field(form, "accent_choice") ?? "none";
+ const accentCustom = normaliseHex(field(form, "accent_custom")) ?? "#eb459e";
+
+ const values: ComposerValues = {
+ title: (field(form, "title") ?? "").trim().slice(0, 200),
+ slug: normaliseSlug(field(form, "slug")),
+ body: normaliseBody(field(form, "body")),
+ language: field(form, "language") ?? "text",
+ theme: field(form, "theme") ?? DEFAULT_THEME,
+ accentChoice,
+ accentCustom,
+ expiry: field(form, "expiry") ?? "never",
+ unlisted: field(form, "unlisted") === "1",
+ };
+
+ const fail = (error: string): Parsed => ({
+ values,
+ error,
+ accent: null,
+ expiresAt: null,
+ });
+
+ if (!values.body) return fail("A paste needs some content.");
+ const size = Buffer.byteLength(values.body, "utf8");
+ if (size > config.maxBodyBytes) {
+ const sizeKb = Math.round(size / 1024);
+ const limitKb = Math.round(config.maxBodyBytes / 1024);
+ return fail(`That paste is ${sizeKb} KB; the limit is ${limitKb} KB.`);
+ }
+
+ if (!isLanguage(values.language)) return fail("That isn't one of the languages on offer.");
+ if (!isTheme(values.theme)) return fail("That isn't one of the highlight themes on offer.");
+
+ const expiryFault = expiryProblem(values.expiry);
+ if (expiryFault) return fail(expiryFault);
+
+ let accent: string | null = null;
+ if (accentChoice === "custom") {
+ const hex = normaliseHex(field(form, "accent_custom"));
+ if (!hex) return fail("That accent colour isn't a valid hex colour.");
+ accent = hex;
+ } else if (accentChoice !== "none") {
+ const preset = ACCENT_PRESETS.find((p) => p.id === accentChoice);
+ if (!preset) return fail("That isn't one of the accent colours on offer.");
+ accent = preset.hex;
+ }
+
+ return {
+ values,
+ error: null,
+ accent,
+ expiresAt: expiresAtFrom(values.expiry),
+ };
+}
+
+/** Generated slugs collide vanishingly rarely; a few tries removes the doubt. */
+export function freeSlug(): string | null {
+ for (let attempt = 0; attempt < 8; attempt++) {
+ const slug = randomSlug(attempt < 5 ? 8 : 12);
+ if (!slugTaken(slug)) return slug;
+ }
+ return null;
+}
+
+/** Resolves a paste the signed-in account is allowed to change, or throws the right error page. */
+export function ownPaste(event: RequestEvent): PasteWithAuthor {
+ const user = event.locals.user;
+ const paste = getPaste(event.params.slug ?? "");
+
+ if (!paste) {
+ error(404, {
+ title: "No such paste",
+ message: "It may have expired, been deleted, or never existed.",
+ });
+ }
+ if (!user) {
+ error(401, {
+ title: "Sign in first",
+ message: "Only the author can change a paste.",
+ });
+ }
+ if (paste.author_id !== user.id) {
+ error(403, {
+ title: "Not yours",
+ message: "Only the author can change this paste.",
+ });
+ }
+ return paste;
+}
+
+/** Throws the "form expired" page when the CSRF token doesn't match. */
+export function formExpired(): never {
+ error(403, {
+ title: "That form expired",
+ message: "Go back, reload the page and try again.",
+ });
+}
diff --git a/src/lib/crypto.ts b/src/lib/server/crypto.ts
similarity index 98%
rename from src/lib/crypto.ts
rename to src/lib/server/crypto.ts
index bc3a171..5afc5d6 100644
--- a/src/lib/crypto.ts
+++ b/src/lib/server/crypto.ts
@@ -1,4 +1,4 @@
-/* src/lib/crypto.ts
+/* src/lib/server/crypto.ts
* 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.
diff --git a/src/db.ts b/src/lib/server/db.ts
similarity index 96%
rename from src/db.ts
rename to src/lib/server/db.ts
index 50fb353..8342362 100644
--- a/src/db.ts
+++ b/src/lib/server/db.ts
@@ -1,4 +1,4 @@
-/* src/db.ts
+/* src/lib/server/db.ts
* 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.
@@ -7,11 +7,15 @@
import { Database } from "bun:sqlite";
import { dirname } from "node:path";
import { mkdirSync } from "node:fs";
-import { config, now } from "./env";
+import { building } from "$app/env";
+import { config, now } from "./env.ts";
-mkdirSync(dirname(config.databaseFile), { recursive: true });
+// The build imports this module to analyse it; it gets a throwaway database
+const file = building ? ":memory:" : config.databaseFile;
-export const db = new Database(config.databaseFile, { create: true, strict: true });
+if (!building) mkdirSync(dirname(file), { recursive: true });
+
+export const db = new Database(file, { create: true, strict: true });
// WAL lets readers (every paste view) run while a write is in flight, which is
// the whole access pattern of a pastebin.
diff --git a/src/env.ts b/src/lib/server/env.ts
similarity index 84%
rename from src/env.ts
rename to src/lib/server/env.ts
index 19a2b9e..4bed3e8 100644
--- a/src/env.ts
+++ b/src/lib/server/env.ts
@@ -1,10 +1,10 @@
-/* src/env.ts
+/* src/lib/server/env.ts
* 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.
*/
-import type { Context } from "hono";
+import { building } from "$app/env";
function required(name: string): string {
const value = process.env[name]?.trim();
@@ -44,14 +44,19 @@ export interface Config {
maxHighlightBytes: number;
}
+// The build imports server modules to analyse them, with no .env around
+const read = building
+ ? (name: string) => process.env[name]?.trim() || "http://localhost"
+ : required;
+
export const config: Config = {
- origin: required("ORIGIN").replace(/\/+$/, ""),
+ origin: read("ORIGIN").replace(/\/+$/, ""),
siteName: optional("SITE_NAME", "Doughmination Paste"),
port: integer("PORT", 3000),
host: optional("HOST", "0.0.0.0"),
databaseFile: optional("DATABASE_FILE", "data/pastebin.db"),
- issuer: required("OIDC_ISSUER").replace(/\/+$/, ""),
- clientId: required("OIDC_CLIENT_ID"),
+ issuer: read("OIDC_ISSUER").replace(/\/+$/, ""),
+ clientId: read("OIDC_CLIENT_ID"),
clientSecret: optional("OIDC_CLIENT_SECRET", ""),
maxBodyBytes: integer("MAX_BODY_BYTES", 512 * 1024),
maxHighlightBytes: integer("MAX_HIGHLIGHT_BYTES", 192 * 1024),
@@ -78,17 +83,6 @@ export interface CurrentUser {
picture: string | null;
}
-export type AppEnv = {
- Variables: {
- session: SessionInfo | null;
- user: CurrentUser | null;
- /** Per-response nonce for the one <style> block the layout emits. */
- nonce: string;
- };
-};
-
-export type AppContext = Context<AppEnv>;
-
export const TTL = {
session: 60 * 60 * 24 * 14,
/** How long a half-finished sign-in may sit at the auth server. */
diff --git a/src/highlight.ts b/src/lib/server/highlight.ts
similarity index 91%
rename from src/highlight.ts
rename to src/lib/server/highlight.ts
index 301a106..8920982 100644
--- a/src/highlight.ts
+++ b/src/lib/server/highlight.ts
@@ -1,13 +1,13 @@
-/* src/highlight.ts
+/* src/lib/server/highlight.ts
* 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.
*/
import { createHighlighter, type Highlighter, type LanguageRegistration } from "shiki";
-import { config } from "./env";
-import { doughminationDark, doughminationLight } from "./themes";
-import jpmlGrammar from "../syntaxes/jpml.tmLanguage.json" with { type: "json" };
+import { config } from "./env.ts";
+import { doughminationDark, doughminationLight } from "./themes.ts";
+import jpmlGrammar from "../../../syntaxes/jpml.tmLanguage.json" with { type: "json" };
/**
* The grammar file is copied verbatim from jpml-vscode so the two stay in
@@ -284,3 +284,25 @@ export async function render(body: string, language: string, theme: string): Pro
export function shouldNumber(lines: number): boolean {
return lines <= MAX_LINES_NUMBERED;
}
+
+const recent = new Map<string, Promise<Rendered>>();
+
+/** The page and its stylesheet both need a paste's render; this keeps the last few around */
+export function renderPaste(paste: {
+ slug: string;
+ updated_at: number;
+ body: string;
+ language: string;
+ theme: string;
+}): Promise<Rendered> {
+ const key = `${paste.slug}:${paste.updated_at}`;
+
+ let rendered = recent.get(key);
+ if (!rendered) {
+ rendered = render(paste.body, paste.language, paste.theme);
+ recent.set(key, rendered);
+ // Oldest out first; a Map iterates in insertion order
+ if (recent.size > 32) recent.delete(recent.keys().next().value!);
+ }
+ return rendered;
+}
diff --git a/src/jpml.ts b/src/lib/server/jpml.ts
similarity index 69%
rename from src/jpml.ts
rename to src/lib/server/jpml.ts
index 80b5d56..272d5bc 100644
--- a/src/jpml.ts
+++ b/src/lib/server/jpml.ts
@@ -1,10 +1,22 @@
-/* src/jpml.ts
+/* src/lib/server/jpml.ts
* 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.
*/
-import { JPDecodeError, loads } from "jpml-lang/core";
+interface JpmlCore {
+ loads(text: string): unknown;
+ JPDecodeError: new (...args: never[]) => Error & {
+ rawMessage: string;
+ line?: number;
+ col?: number;
+ };
+}
+
+// jpml-lang left the npm registry, so the parser is optional: without it there's no check
+const PACKAGE = "jpml-lang/core";
+
+const core: Promise<JpmlCore | null> = import(/* @vite-ignore */ PACKAGE).catch(() => null);
/**
* Pastes tagged `jpml` are run through the real parser, so the page can say
@@ -24,9 +36,13 @@ export interface JpmlCheck {
/** Documents past this size are skipped: the check is a nicety, not worth the stall. */
const MAX_CHECK_BYTES = 256 * 1024;
-export function check(body: string): JpmlCheck | null {
+export async function check(body: string): Promise<JpmlCheck | null> {
if (Buffer.byteLength(body, "utf8") > MAX_CHECK_BYTES) return null;
+ const parser = await core;
+ if (!parser) return null;
+ const { JPDecodeError, loads } = parser;
+
try {
// Duplicate keys are an error in the parser's default mode, which matches
// what the VS Code extension reports out of the box.
diff --git a/src/lib/server/listing.ts b/src/lib/server/listing.ts
new file mode 100644
index 0000000..0f6acae
--- /dev/null
+++ b/src/lib/server/listing.ts
@@ -0,0 +1,28 @@
+/* src/lib/server/listing.ts
+ * 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.
+ */
+
+import type { PasteWithAuthor } from "./db.ts";
+import { languageLabel } from "./highlight.ts";
+
+export const PER_PAGE = 25;
+
+export function pageNumber(url: URL): number {
+ const raw = Number(url.searchParams.get("page") ?? "1");
+ return Number.isFinite(raw) && raw >= 1 ? Math.floor(raw) : 1;
+}
+
+/** Just what a listing row shows; the body never leaves the server here */
+export function toRow(paste: PasteWithAuthor) {
+ return {
+ slug: paste.slug,
+ title: paste.title,
+ languageLabel: languageLabel(paste.language),
+ author: paste.author_name ?? paste.author_username,
+ created_at: paste.created_at,
+ unlisted: paste.unlisted,
+ expires_at: paste.expires_at,
+ };
+}
diff --git a/src/auth/oidc.ts b/src/lib/server/oidc.ts
similarity index 98%
rename from src/auth/oidc.ts
rename to src/lib/server/oidc.ts
index 56fb8d6..eb9129f 100644
--- a/src/auth/oidc.ts
+++ b/src/lib/server/oidc.ts
@@ -1,11 +1,11 @@
-/* src/auth/oidc.ts
+/* src/lib/server/oidc.ts
* 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.
*/
import { createRemoteJWKSet, jwtVerify, type JWTPayload } from "jose";
-import { config, redirectUri } from "../env";
+import { config, redirectUri } from "./env.ts";
interface Discovery {
issuer: string;
diff --git a/src/lib/server/session.ts b/src/lib/server/session.ts
new file mode 100644
index 0000000..9dee2e9
--- /dev/null
+++ b/src/lib/server/session.ts
@@ -0,0 +1,83 @@
+/* src/lib/server/session.ts
+ * 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.
+ */
+
+import type { Cookies, RequestEvent } from "@sveltejs/kit";
+import { TTL, isSecure, now } from "./env.ts";
+import { randomToken, sha256Hex, timingSafeEqualStr } from "./crypto.ts";
+import { createSession, deleteSession, getSession, getUser } from "./db.ts";
+
+const COOKIE = "paste_session";
+
+/**
+ * Only the hash of the cookie value is stored, so a copy of the database
+ * doesn't hand anyone a working session.
+ */
+export async function startSession(cookies: Cookies, userId: string): Promise<void> {
+ const token = randomToken(32);
+ const expiresAt = now() + TTL.session;
+ createSession(await sha256Hex(token), userId, randomToken(16), expiresAt);
+
+ cookies.set(COOKIE, token, {
+ httpOnly: true,
+ secure: isSecure(),
+ sameSite: "lax",
+ path: "/",
+ maxAge: TTL.session,
+ });
+}
+
+export function endCurrentSession(event: RequestEvent): void {
+ const session = event.locals.session;
+ if (session) deleteSession(session.idHash);
+ event.cookies.delete(COOKIE, {
+ path: "/",
+ secure: isSecure(),
+ });
+}
+
+/** Puts the signed-in user (or null) on locals for every request. */
+export async function loadSession(event: RequestEvent): Promise<void> {
+ event.locals.session = null;
+ event.locals.user = null;
+
+ const token = event.cookies.get(COOKIE);
+ if (!token) return;
+
+ const row = getSession(await sha256Hex(token));
+ if (!row) {
+ event.cookies.delete(COOKIE, {
+ path: "/",
+ secure: isSecure(),
+ });
+ return;
+ }
+
+ const user = getUser(row.user_id);
+ if (!user) {
+ deleteSession(row.id_hash);
+ return;
+ }
+
+ event.locals.session = {
+ idHash: row.id_hash,
+ userId: row.user_id,
+ csrf: row.csrf,
+ expiresAt: row.expires_at,
+ };
+ event.locals.user = {
+ id: user.id,
+ username: user.username,
+ name: user.name,
+ picture: user.picture,
+ };
+}
+
+/** Second CSRF layer, behind the Origin check in hooks.server.ts. */
+export function csrfOk(event: RequestEvent, submitted: FormDataEntryValue | null): boolean {
+ const session = event.locals.session;
+ if (!session || typeof submitted !== "string" || !submitted) return false;
+ return timingSafeEqualStr(submitted, session.csrf);
+}
diff --git a/src/themes.ts b/src/lib/server/themes.ts
similarity index 99%
rename from src/themes.ts
rename to src/lib/server/themes.ts
index 98858c0..cd78a96 100644
--- a/src/themes.ts
+++ b/src/lib/server/themes.ts
@@ -1,4 +1,4 @@
-/* src/themes.ts
+/* src/lib/server/themes.ts
* 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.
diff --git a/src/lib/validate.ts b/src/lib/server/validate.ts
similarity index 85%
rename from src/lib/validate.ts
rename to src/lib/server/validate.ts
index 42791ba..e00134c 100644
--- a/src/lib/validate.ts
+++ b/src/lib/server/validate.ts
@@ -1,10 +1,10 @@
-/* src/lib/validate.ts
+/* src/lib/server/validate.ts
* 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.
*/
-import { now } from "../env";
+import { now } from "./env.ts";
// Slugs are the whole URL after the origin, so they stay lowercase and boring:
// 3–64 characters, letters, digits, dashes and underscores, no leading or
@@ -29,6 +29,9 @@ export const RESERVED_SLUGS = new Set([
"edit",
"delete",
"favicon.ico",
+ "favicon.svg",
+ "background.avif",
+ "_app",
"robots.txt",
"health",
"u",
@@ -94,3 +97,11 @@ export function expiryIdFrom(expiresAt: number | null): string {
const match = EXPIRY_OPTIONS.filter((o) => o.seconds !== null).find((o) => o.seconds! >= remaining);
return match?.id ?? "1y";
}
+
+/** Only same-site paths: "/x" yes, "//host", "/\host" and absolute URLs no. */
+export function safeReturn(raw: unknown, fallback = "/"): string {
+ if (typeof raw !== "string" || !raw.startsWith("/")) return fallback;
+ if (raw.startsWith("//") || raw.startsWith("/\\")) return fallback;
+ if (/[\x00-\x20]/.test(raw)) return fallback;
+ return raw.length > 2048 ? fallback : raw;
+}
diff --git a/src/lib/styles/fonts.css b/src/lib/styles/fonts.css
new file mode 100644
index 0000000..b9e8daf
--- /dev/null
+++ b/src/lib/styles/fonts.css
@@ -0,0 +1,69 @@
+/* src/lib/styles/fonts.css
+ * 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.
+ */
+
+/* IBM Plex Sans for text, same files as doughmination.gay */
+
+@font-face {
+ font-family: "IBM Plex Sans";
+ src: url("../fonts/IBMPlexSans-Regular.woff2") format("woff2");
+ font-weight: 400;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "IBM Plex Sans";
+ src: url("../fonts/IBMPlexSans-Medium.woff2") format("woff2");
+ font-weight: 500;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "IBM Plex Sans";
+ src: url("../fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
+ font-weight: 600;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "IBM Plex Sans";
+ src: url("../fonts/IBMPlexSans-Bold.woff2") format("woff2");
+ font-weight: 700;
+ font-display: swap;
+}
+
+/* Comic Code for anything monospace */
+
+@font-face {
+ font-family: "Comic Code";
+ src: url("https://raw.doughmination.gay/f/Comic-Code/woff2/ComicCode-Regular.woff2") format("woff2");
+ font-weight: 400;
+ font-style: normal;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "Comic Code";
+ src: url("https://raw.doughmination.gay/f/Comic-Code/woff2/ComicCode-Italic.woff2") format("woff2");
+ font-weight: 400;
+ font-style: italic;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "Comic Code";
+ src: url("https://raw.doughmination.gay/f/Comic-Code/woff2/ComicCode-Medium.woff2") format("woff2");
+ font-weight: 500;
+ font-style: normal;
+ font-display: swap;
+}
+
+@font-face {
+ font-family: "Comic Code";
+ src: url("https://raw.doughmination.gay/f/Comic-Code/woff2/ComicCode-Bold.woff2") format("woff2");
+ font-weight: 700;
+ font-style: normal;
+ font-display: swap;
+}
diff --git a/src/lib/styles/footer.css b/src/lib/styles/footer.css
new file mode 100644
index 0000000..de6a668
--- /dev/null
+++ b/src/lib/styles/footer.css
@@ -0,0 +1,124 @@
+/* src/lib/styles/footer.css
+ * 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.
+ */
+
+/* Sits in the page flow; margin-top: auto pins it to the bottom of short pages */
+footer {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 1rem 1.5rem;
+ align-items: center;
+ justify-content: space-between;
+ width: 100%;
+ max-width: 62rem;
+ margin: auto auto 0;
+ padding: 1.25rem 1.5rem;
+ border-top: 1px solid var(--line);
+ color: var(--muted);
+ font-size: 0.85rem;
+}
+
+.footer-line {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.25rem 0.75rem;
+ align-items: center;
+ margin: 0;
+}
+
+.footer-line > span {
+ display: inline-flex;
+ gap: 0.4em;
+ align-items: center;
+}
+
+/* Dot between items, skipped on the first */
+.footer-line > span + span::before {
+ content: "·";
+ margin-right: 0.75rem;
+ color: var(--line);
+}
+
+.footer-brand img {
+ border-radius: 50%;
+}
+
+/* Heart */
+
+.beat {
+ color: var(--accent);
+ animation: beat 1.2s ease-in-out infinite;
+}
+
+.beat svg {
+ width: 1em;
+ height: 1em;
+}
+
+/* Two quick pulses, then a rest, like a heartbeat */
+@keyframes beat {
+ 0%,
+ 40%,
+ 100% {
+ transform: scale(1);
+ }
+ 10%,
+ 30% {
+ transform: scale(1.25);
+ }
+ 20% {
+ transform: scale(1.05);
+ }
+}
+
+/* "Not by AI" badge */
+
+.no-ai {
+ line-height: 0;
+}
+
+.no-ai img {
+ display: block;
+ transition: filter 0.2s ease;
+}
+
+.no-ai:hover img {
+ filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 55%, transparent));
+}
+
+.no-ai:focus-visible {
+ outline: 2px solid var(--accent);
+ outline-offset: 2px;
+}
+
+/* Narrow screens: stack and centre */
+@media (max-width: 40rem) {
+ footer,
+ .footer-line {
+ flex-direction: column;
+ justify-content: center;
+ text-align: center;
+ }
+
+ .footer-line > span + span::before {
+ content: none;
+ }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .beat {
+ animation: none;
+ }
+
+ .no-ai img {
+ transition: none;
+ }
+}
+
+@media print {
+ footer {
+ display: none;
+ }
+}
\ No newline at end of file
diff --git a/src/lib/styles/global.css b/src/lib/styles/global.css
new file mode 100644
index 0000000..ae7bb07
--- /dev/null
+++ b/src/lib/styles/global.css
@@ -0,0 +1,123 @@
+/* src/lib/styles/global.css
+ * 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.
+ */
+
+* {
+ box-sizing: border-box;
+}
+
+/* <iconsax-icon> renders its <svg> inside itself, so size that via `... svg` selectors */
+iconsax-icon {
+ display: inline-flex;
+ flex-shrink: 0;
+}
+
+html {
+ height: 100%;
+}
+
+body {
+ display: flex;
+ position: relative;
+ flex-direction: column;
+ min-height: 100%;
+ margin: 0;
+ font-size: 1rem;
+ line-height: 1.6;
+}
+
+/* Keeps page sections laid out as before they were wrapped in <main> */
+main {
+ display: flex;
+ flex-direction: column;
+}
+
+a {
+ color: var(--text);
+ text-decoration-color: rgb(235 69 158 / 55%);
+ text-underline-offset: 0.2em;
+}
+
+a:hover {
+ color: #fff;
+ text-decoration-color: var(--accent);
+}
+
+h1 {
+ line-height: 1.25;
+ text-wrap: balance;
+}
+
+br {
+ display: block;
+ content: "";
+ margin-bottom: 1em;
+}
+
+/* Hero */
+
+/* The background image lives in the header"s .backdrop */
+.hero {
+ padding-block: 4rem 2rem;
+}
+
+.eyebrow {
+ margin: 0 0 0.5rem;
+ color: var(--accent);
+ font-size: 0.75rem;
+ font-weight: 600;
+ letter-spacing: 0.14em;
+ text-transform: uppercase;
+}
+
+.hero h1 {
+ margin: 0 0 0.25rem;
+ font-size: clamp(2.75rem, 9vw, 4.5rem);
+ font-weight: 700;
+ letter-spacing: -0.03em;
+}
+
+.subtitle {
+ margin: 0 0 1.25rem;
+ color: var(--muted);
+ font-size: clamp(1.05rem, 2.5vw, 1.25rem);
+}
+
+.lede {
+ max-width: 36rem;
+ margin: 0 0 2rem;
+ color: #cfc9d6;
+}
+
+.intro {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 1.5rem 2.5rem;
+ align-items: flex-start;
+}
+
+.intro .lede {
+ flex: 1 1 20rem;
+ margin: 0;
+}
+
+.wrap {
+ width: 100%;
+ max-width: 62rem;
+ margin: 0 auto;
+ padding-inline: 1.5rem;
+}
+
+@media print {
+ .hero {
+ display: none;
+ }
+ .lede {
+ display: none;
+ }
+ .wrap {
+ display: none;
+ }
+}
\ No newline at end of file
diff --git a/src/lib/styles/header.css b/src/lib/styles/header.css
new file mode 100644
index 0000000..d62d8fe
--- /dev/null
+++ b/src/lib/styles/header.css
@@ -0,0 +1,96 @@
+/* src/lib/styles/header.css
+ * 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.
+ */
+
+/* Backdrop */
+
+.backdrop {
+ position: absolute;
+ top: 0;
+ right: 0;
+ left: 0;
+ z-index: -1;
+ height: 30rem;
+ overflow: hidden;
+ pointer-events: none;
+}
+
+.backdrop::before {
+ content: "";
+ position: absolute;
+ inset: 0;
+ background: url("/background.avif") center / cover no-repeat;
+ opacity: 0.5;
+}
+
+.backdrop::after {
+ content: "";
+ position: absolute;
+ inset: 0;
+ background:
+ linear-gradient(rgb(11 10 13 / 55%), rgb(11 10 13 / 80%) 55%, var(--bg)),
+ radial-gradient(70% 60% at 20% 30%, rgb(235 69 158 / 12%), transparent 70%);
+}
+
+/* Top bar */
+
+header {
+ position: relative;
+ z-index: 2;
+ display: flex;
+ flex-wrap: wrap;
+ gap: 1rem 1.5rem;
+ align-items: center;
+ justify-content: space-between;
+ width: 100%;
+ max-width: 62rem;
+ margin: 0 auto;
+ padding: 1.25rem 1.5rem;
+}
+
+header nav {
+ display: flex;
+ gap: 1.25rem;
+ font-size: 0.9rem;
+}
+
+header nav a {
+ display: inline-flex;
+ gap: 0.4em;
+ align-items: center;
+ color: var(--muted);
+ text-decoration: none;
+}
+
+header nav a:hover {
+ color: var(--text);
+}
+
+.brand {
+ display: inline-flex;
+ gap: 0.6rem;
+ align-items: center;
+ font-weight: 600;
+ letter-spacing: 0.01em;
+ text-decoration: none;
+}
+
+.brand img {
+ border-radius: 50%;
+ outline: 1px solid var(--line);
+}
+
+.nav-icon,
+.nav-icon svg {
+ width: 1.2em;
+ height: 1.2em;
+ flex-shrink: 0;
+}
+
+@media print {
+ header{
+ display: none;
+ }
+}
\ No newline at end of file
diff --git a/src/lib/styles/theme.css b/src/lib/styles/theme.css
new file mode 100644
index 0000000..02aaeba
--- /dev/null
+++ b/src/lib/styles/theme.css
@@ -0,0 +1,29 @@
+/* src/lib/styles/theme.css
+ * 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.
+ */
+
+/* doughmination.gay's tokens, plus the few an app needs on top */
+:root {
+ --bg: #0b0a0d;
+ --raised: rgb(255 255 255 / 3.5%);
+ --line: rgb(255 255 255 / 9%);
+ --text: #ece9ef;
+ --muted: #a49eab;
+ --accent: #eb459e;
+ --accent-dim: rgb(235 69 158 / 14%);
+ --accent-line: rgb(235 69 158 / 40%);
+
+ --ok: #7fd98b;
+ --warn: #f2c46d;
+ --bad: #ff8a9a;
+ --on-accent: #1a0611;
+
+ --mono: "Comic Code", ui-monospace, "Cascadia Code", Menlo, monospace;
+
+ color-scheme: dark;
+ font-family: "IBM Plex Sans", system-ui, sans-serif;
+ background: var(--bg);
+ color: var(--text);
+}
diff --git a/src/lib/styles/ui.css b/src/lib/styles/ui.css
new file mode 100644
index 0000000..aa2cac1
--- /dev/null
+++ b/src/lib/styles/ui.css
@@ -0,0 +1,346 @@
+/* src/lib/styles/ui.css
+ * 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.
+ */
+
+/* App controls in the doughmination.gay look: raised surfaces, hairlines, accent rings */
+
+/* app.html's wrapper; a class, since the CSP allows no style attributes */
+.app {
+ display: contents;
+}
+
+/* Monospace */
+
+code,
+kbd,
+pre,
+samp {
+ font-family: var(--mono);
+ font-size: 0.9em;
+}
+
+::selection {
+ background: var(--accent);
+ color: var(--on-accent);
+}
+
+/* Page width, same as the header and footer */
+
+.page {
+ display: flex;
+ flex-direction: column;
+ gap: 1.25rem;
+ width: 100%;
+ max-width: 62rem;
+ margin: 0 auto;
+ padding: 2rem 1.5rem 3rem;
+}
+
+.page.narrow {
+ max-width: 34rem;
+}
+
+.page-head h1 {
+ margin: 0;
+ font-size: clamp(1.75rem, 5vw, 2.5rem);
+ font-weight: 700;
+ letter-spacing: -0.02em;
+}
+
+.page-head p {
+ margin: 0.25rem 0 0;
+}
+
+/* Panels: web's .card without the hover lift, for things you work in */
+
+.panel {
+ display: flex;
+ flex-direction: column;
+ gap: 0.75rem;
+ padding: 1.25rem 1.5rem;
+ border: 1px solid var(--line);
+ border-radius: 1rem;
+ background: var(--raised);
+}
+
+.panel h2 {
+ margin: 0;
+ font-size: 1.15rem;
+ font-weight: 600;
+}
+
+/* Buttons */
+
+button,
+.btn {
+ display: inline-flex;
+ gap: 0.4em;
+ align-items: center;
+ justify-content: center;
+ padding: 0.4rem 0.9rem;
+ border: 1px solid var(--line);
+ /* Soft corners: a full pill curve clips text once a button wraps */
+ border-radius: 0.75rem;
+ background: var(--raised);
+ color: inherit;
+ font: inherit;
+ font-size: 0.9rem;
+ line-height: 1.35;
+ text-decoration: none;
+ cursor: pointer;
+ transition:
+ border-color 0.15s ease,
+ background 0.15s ease,
+ color 0.15s ease,
+ filter 0.15s ease;
+}
+
+button:hover:not(:disabled),
+.btn:hover:not([aria-disabled="true"]) {
+ border-color: var(--accent-line);
+ color: var(--text);
+}
+
+button:disabled,
+.btn[aria-disabled="true"] {
+ opacity: 0.4;
+ cursor: default;
+}
+
+button.primary,
+.btn.primary {
+ border-color: var(--accent);
+ background: var(--accent);
+ color: var(--on-accent);
+ font-weight: 600;
+}
+
+button.primary:hover:not(:disabled),
+.btn.primary:hover {
+ color: var(--on-accent);
+ filter: brightness(1.12);
+}
+
+button.danger,
+.btn.danger {
+ color: var(--bad);
+}
+
+button.danger:hover:not(:disabled) {
+ border-color: var(--bad);
+}
+
+button.small,
+.btn.small {
+ padding: 0.25rem 0.7rem;
+ font-size: 0.82rem;
+}
+
+button iconsax-icon svg,
+.btn iconsax-icon svg {
+ width: 1.1em;
+ height: 1.1em;
+}
+
+.buttons {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.5rem;
+ align-items: center;
+}
+
+form.inline {
+ display: inline;
+}
+
+/* Fields */
+
+input,
+select,
+textarea {
+ width: 100%;
+ padding: 0.5rem 0.75rem;
+ border: 1px solid var(--line);
+ border-radius: 0.75rem;
+ background: rgb(0 0 0 / 25%);
+ color: var(--text);
+ font: inherit;
+}
+
+textarea {
+ min-height: 12rem;
+ font-family: var(--mono);
+ font-size: 0.875rem;
+ line-height: 1.55;
+ tab-size: 2;
+ resize: vertical;
+}
+
+input[type="checkbox"],
+input[type="radio"] {
+ width: auto;
+ accent-color: var(--accent);
+}
+
+input[readonly],
+input:disabled {
+ color: var(--muted);
+}
+
+:focus-visible {
+ outline: 2px solid var(--accent);
+ outline-offset: 2px;
+}
+
+input:focus-visible,
+select:focus-visible,
+textarea:focus-visible {
+ outline-offset: 0;
+ border-color: var(--accent-line);
+}
+
+.field {
+ display: flex;
+ flex-direction: column;
+ gap: 0.35rem;
+}
+
+.field > span,
+.field > legend {
+ color: var(--muted);
+ font-size: 0.75rem;
+ font-weight: 600;
+ letter-spacing: 0.1em;
+ text-transform: uppercase;
+}
+
+fieldset {
+ margin: 0;
+ padding: 0;
+ border: 0;
+}
+
+legend {
+ padding: 0;
+}
+
+.check {
+ display: flex;
+ gap: 0.6rem;
+ align-items: flex-start;
+}
+
+.check input {
+ margin-top: 0.35rem;
+}
+
+.stack {
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+}
+
+.grid2 {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
+ gap: 1rem;
+}
+
+/* Notices and badges */
+
+.notice {
+ margin: 0;
+ padding: 0.65rem 1rem;
+ border: 1px solid var(--line);
+ border-radius: 0.75rem;
+ background: var(--raised);
+}
+
+.notice.ok {
+ border-color: rgb(127 217 139 / 40%);
+ background: rgb(127 217 139 / 8%);
+}
+
+.notice.error {
+ border-color: rgb(255 138 154 / 45%);
+ background: rgb(255 138 154 / 8%);
+}
+
+.badge {
+ display: inline-block;
+ padding: 0.05rem 0.55rem;
+ border: 1px solid var(--line);
+ border-radius: 999px;
+ color: var(--muted);
+ font-size: 0.75rem;
+ white-space: nowrap;
+}
+
+.badge.accent {
+ border-color: var(--accent-line);
+ background: var(--accent-dim);
+ color: var(--accent);
+}
+
+.badge.danger {
+ border-color: rgb(255 138 154 / 45%);
+ color: var(--bad);
+}
+
+/* Lists of rows */
+
+.rows {
+ margin: 0;
+ padding: 0;
+ list-style: none;
+}
+
+.rows > li {
+ display: flex;
+ gap: 0.75rem;
+ align-items: center;
+ padding: 0.7rem 0;
+ border-bottom: 1px solid var(--line);
+}
+
+.rows > li:last-child {
+ border-bottom: 0;
+}
+
+.meta {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 0.4rem;
+ align-items: center;
+ margin: 0.15rem 0 0;
+}
+
+.pager {
+ display: flex;
+ gap: 0.75rem;
+ align-items: center;
+}
+
+/* Text helpers */
+
+.muted {
+ color: var(--muted);
+}
+
+.small {
+ font-size: 0.85rem;
+}
+
+.grow {
+ flex: 1;
+ min-width: 0;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ button,
+ .btn {
+ transition: none;
+ }
+}
diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte
new file mode 100644
index 0000000..f79fc37
--- /dev/null
+++ b/src/routes/+error.svelte
@@ -0,0 +1,42 @@
+<!-- src/routes/+error.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 { siteName } from "#lib";
+
+ const notFound = $derived(page.status === 404 && !page.error?.title);
+ const title = $derived(page.error?.title ?? (notFound ? "Not found" : "Something went wrong"));
+ const message = $derived(notFound ? "There's nothing at that address." : page.error?.message);
+</script>
+
+<svelte:head>
+ <title>{title} · {siteName}</title>
+ <meta name="robots" content="noindex" />
+</svelte:head>
+
+<div class="page narrow">
+ <section class="panel">
+ <p class="eyebrow">Error {page.status}</p>
+ <h1>{title}</h1>
+ <p class="muted">{message}</p>
+ <p>
+ <a class="btn" href="/">
+ <iconsax-icon name="arrow-left-01" type="bulk" size="18"></iconsax-icon>Back to recent pastes
+ </a>
+ </p>
+ </section>
+</div>
+
+<style>
+ h1 {
+ margin: 0;
+ }
+
+ p {
+ margin: 0;
+ }
+</style>
diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts
new file mode 100644
index 0000000..752c4e0
--- /dev/null
+++ b/src/routes/+layout.server.ts
@@ -0,0 +1,20 @@
+/* src/routes/+layout.server.ts
+ * 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.
+ */
+
+import type { LayoutServerLoad } from "./$types";
+
+export const load: LayoutServerLoad = ({ locals }) => {
+ const user = locals.user;
+ return {
+ user: user
+ ? {
+ username: user.username,
+ name: user.name,
+ }
+ : null,
+ csrf: locals.session?.csrf ?? "",
+ };
+};
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
new file mode 100644
index 0000000..826da5a
--- /dev/null
+++ b/src/routes/+layout.svelte
@@ -0,0 +1,22 @@
+<!-- src/routes/+layout.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 "#lib/styles/fonts.css";
+ import "#lib/styles/theme.css";
+ import "#lib/styles/global.css";
+ import "#lib/styles/ui.css";
+ import Header from "#lib/components/Header.svelte";
+ import Footer from "#lib/components/Footer.svelte";
+
+ let { data, children } = $props();
+</script>
+
+<Header user={data.user} csrf={data.csrf} />
+<main>
+ {@render children()}
+</main>
+<Footer />
diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts
new file mode 100644
index 0000000..4f867a2
--- /dev/null
+++ b/src/routes/+page.server.ts
@@ -0,0 +1,19 @@
+/* src/routes/+page.server.ts
+ * 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.
+ */
+
+import type { PageServerLoad } from "./$types";
+import { countPastes, listPastes } from "#lib/server/db.ts";
+import { PER_PAGE, pageNumber, toRow } from "#lib/server/listing.ts";
+
+export const load: PageServerLoad = ({ url }) => {
+ const page = pageNumber(url);
+ return {
+ page,
+ total: countPastes(),
+ perPage: PER_PAGE,
+ pastes: listPastes(PER_PAGE, (page - 1) * PER_PAGE).map(toRow),
+ };
+};
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
new file mode 100644
index 0000000..dc75617
--- /dev/null
+++ b/src/routes/+page.svelte
@@ -0,0 +1,36 @@
+<!-- src/routes/+page.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 { siteName } from "#lib";
+ import Flash from "#lib/components/Flash.svelte";
+ import Pager from "#lib/components/Pager.svelte";
+ import PasteRows from "#lib/components/PasteRows.svelte";
+
+ let { data } = $props();
+</script>
+
+<svelte:head>
+ <title>Recent pastes · {siteName}</title>
+ <meta name="description" content="Public pastes on {siteName}." />
+</svelte:head>
+
+<div class="page">
+ <div class="page-head">
+ <p class="eyebrow">Pastebin</p>
+ <h1>Recent pastes</h1>
+ <p class="muted">
+ Anyone can read what's here. {data.user ? "Publish one from New paste." : "Sign in to publish one."}
+ </p>
+ </div>
+
+ <Flash />
+
+ <section class="panel">
+ <PasteRows pastes={data.pastes} empty="Nothing published yet." />
+ <Pager path="/" page={data.page} total={data.total} perPage={data.perPage} />
+ </section>
+</div>
diff --git a/src/routes/[slug]/+page.server.ts b/src/routes/[slug]/+page.server.ts
new file mode 100644
index 0000000..0adf91e
--- /dev/null
+++ b/src/routes/[slug]/+page.server.ts
@@ -0,0 +1,68 @@
+/* src/routes/[slug]/+page.server.ts
+ * 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.
+ */
+
+import { error, redirect } from "@sveltejs/kit";
+import type { Actions, PageServerLoad } from "./$types";
+import { deletePaste, getPaste } from "#lib/server/db.ts";
+import { csrfOk } from "#lib/server/session.ts";
+import { formExpired, ownPaste } from "#lib/server/compose.ts";
+import { check as checkJpml } from "#lib/server/jpml.ts";
+import {
+ languageLabel,
+ renderPaste,
+ shouldNumber,
+ themeIsLight,
+} from "#lib/server/highlight.ts";
+
+export const load: PageServerLoad = async ({ params, locals }) => {
+ const paste = getPaste(params.slug);
+ if (!paste) {
+ error(404, {
+ title: "No such paste",
+ message: "It may have expired, been deleted, or never existed.",
+ });
+ }
+
+ const rendered = await renderPaste(paste);
+ const jpml = paste.language === "jpml" ? await checkJpml(paste.body) : null;
+
+ return {
+ paste: {
+ slug: paste.slug,
+ title: paste.title,
+ author: paste.author_name ?? paste.author_username,
+ authorUsername: paste.author_username,
+ language: paste.language,
+ languageLabel: languageLabel(paste.language),
+ unlisted: paste.unlisted === 1,
+ createdAt: paste.created_at,
+ updatedAt: paste.updated_at,
+ expiresAt: paste.expires_at,
+ size: Buffer.byteLength(paste.body, "utf8"),
+ },
+ html: rendered.html,
+ lines: rendered.lines,
+ numbered: shouldNumber(rendered.lines),
+ highlighted: rendered.highlighted,
+ light: themeIsLight(paste.theme),
+ // Shiki's classes and the accent live in a stylesheet of their own: the CSP allows no inline styles
+ styled: rendered.css !== "" || paste.accent !== null,
+ jpml,
+ isOwner: locals.user?.id === paste.author_id,
+ };
+};
+
+export const actions: Actions = {
+ delete: async (event) => {
+ const paste = ownPaste(event);
+
+ const form = await event.request.formData();
+ if (!csrfOk(event, form.get("_csrf"))) formExpired();
+
+ deletePaste(paste.slug);
+ redirect(303, "/mine?m=paste-deleted");
+ },
+};
diff --git a/src/routes/[slug]/+page.svelte b/src/routes/[slug]/+page.svelte
new file mode 100644
index 0000000..2f475a8
--- /dev/null
+++ b/src/routes/[slug]/+page.svelte
@@ -0,0 +1,163 @@
+<!-- src/routes/[slug]/+page.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 { siteName } from "#lib";
+ import { bytes, date, relative } from "#lib/format.ts";
+ import Flash from "#lib/components/Flash.svelte";
+ import CodeView from "#lib/components/CodeView.svelte";
+
+ let { data } = $props();
+
+ const paste = $derived(data.paste);
+ const title = $derived(paste.title ?? paste.slug);
+
+ let copyLabel = $state("Copy");
+ let armed = $state(false);
+ let code: CodeView;
+
+ function flash(text: string) {
+ copyLabel = text;
+ setTimeout(() => (copyLabel = "Copy"), 1500);
+ }
+
+ async function copy() {
+ try {
+ await navigator.clipboard.writeText(code.text());
+ flash("Copied");
+ } catch {
+ flash("Press Ctrl+C");
+ }
+ }
+
+ // Deleting can't be undone, so ask once. The form still submits normally without scripting
+ function confirmDelete(event: SubmitEvent) {
+ if (armed) return;
+ event.preventDefault();
+ armed = true;
+ setTimeout(() => (armed = false), 4000);
+ }
+</script>
+
+<svelte:head>
+ <title>{title} · {siteName}</title>
+ <meta name="description" content={paste.title ?? `A paste by ${paste.authorUsername}.`} />
+ {#if paste.unlisted}
+ <meta name="robots" content="noindex" />
+ {/if}
+ {#if data.styled}
+ <link rel="stylesheet" href="/{paste.slug}/style.css?v={paste.updatedAt}" />
+ {/if}
+</svelte:head>
+
+<div class="page">
+ <Flash />
+
+ <article class="paste">
+ <div class="paste-head">
+ <div class="grow">
+ <p class="eyebrow">{paste.languageLabel}</p>
+ <h1>{title}</h1>
+ <p class="muted small meta">
+ <span>by <strong>{paste.author}</strong></span>
+ <span aria-hidden="true">·</span>
+ <span title={date(paste.createdAt)}>{relative(paste.createdAt)}</span>
+ {#if paste.updatedAt !== paste.createdAt}
+ <span aria-hidden="true">·</span>
+ <span title={date(paste.updatedAt)}>edited {relative(paste.updatedAt)}</span>
+ {/if}
+ <span aria-hidden="true">·</span>
+ <span>{data.lines} {data.lines === 1 ? "line" : "lines"}, {bytes(paste.size)}</span>
+ {#if paste.unlisted}
+ <span class="badge">unlisted</span>
+ {/if}
+ {#if paste.expiresAt !== null}
+ <span class="badge danger" title={date(paste.expiresAt)}>expires {relative(paste.expiresAt)}</span>
+ {/if}
+ </p>
+ </div>
+
+ <div class="buttons">
+ <button type="button" class="small" title="Copy the paste to the clipboard" onclick={copy}>
+ <iconsax-icon name="copy" type="bulk" size="16"></iconsax-icon>{copyLabel}
+ </button>
+ <a class="btn small" href="/raw/{paste.slug}">
+ <iconsax-icon name="document-code" type="bulk" size="16"></iconsax-icon>Raw
+ </a>
+ <a class="btn small" href="/dl/{paste.slug}">
+ <iconsax-icon name="document-download" type="bulk" size="16"></iconsax-icon>Download
+ </a>
+ {#if data.isOwner}
+ <a class="btn small" href="/{paste.slug}/edit">
+ <iconsax-icon name="edit-2" type="bulk" size="16"></iconsax-icon>Edit
+ </a>
+ <form method="post" action="?/delete" class="inline" onsubmit={confirmDelete}>
+ <input type="hidden" name="_csrf" value={data.csrf} />
+ <button type="submit" class="small danger">
+ <iconsax-icon name="trash" type="bulk" size="16"></iconsax-icon>{armed ? "Really delete?" : "Delete"}
+ </button>
+ </form>
+ {/if}
+ </div>
+ </div>
+
+ {#if data.jpml && !data.jpml.ok}
+ <p class="notice error" role="status">
+ <strong>JPML:</strong>
+ {data.jpml.message}
+ {#if data.jpml.line !== undefined}
+ at <a href="#L{data.jpml.line}">line {data.jpml.line}</a>{#if data.jpml.col !== undefined}, column {data.jpml.col}{/if}
+ {/if}
+ </p>
+ {:else if data.jpml?.ok}
+ <p class="notice ok" role="status"><strong>JPML:</strong> this document parses cleanly.</p>
+ {/if}
+
+ {#if !data.highlighted && paste.language !== "text"}
+ <p class="notice">Too large to highlight — showing it as plain text.</p>
+ {/if}
+
+ <CodeView
+ bind:this={code}
+ html={data.html}
+ numbered={data.numbered}
+ light={data.light && data.highlighted}
+ />
+ </article>
+</div>
+
+<style>
+ .paste {
+ display: flex;
+ flex-direction: column;
+ gap: 0.75rem;
+ }
+
+ .paste-head {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 1rem;
+ align-items: flex-start;
+ justify-content: space-between;
+ }
+
+ .paste-head h1 {
+ margin: 0;
+ font-size: clamp(1.6rem, 4vw, 2.25rem);
+ letter-spacing: -0.02em;
+ overflow-wrap: anywhere;
+ }
+
+ .eyebrow {
+ margin: 0 0 0.25rem;
+ }
+
+ @media (max-width: 40rem) {
+ .paste-head {
+ flex-direction: column;
+ }
+ }
+</style>
diff --git a/src/routes/[slug]/edit/+page.server.ts b/src/routes/[slug]/edit/+page.server.ts
new file mode 100644
index 0000000..738d9ac
--- /dev/null
+++ b/src/routes/[slug]/edit/+page.server.ts
@@ -0,0 +1,58 @@
+/* src/routes/[slug]/edit/+page.server.ts
+ * 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.
+ */
+
+import { redirect, fail } from "@sveltejs/kit";
+import type { Actions, PageServerLoad } from "./$types";
+import { updatePaste } from "#lib/server/db.ts";
+import { csrfOk } from "#lib/server/session.ts";
+import { cleanText } from "#lib/server/validate.ts";
+import {
+ composerOptions,
+ formExpired,
+ ownPaste,
+ parseComposer,
+ valuesFrom,
+} from "#lib/server/compose.ts";
+
+export const load: PageServerLoad = (event) => {
+ const paste = ownPaste(event);
+ return {
+ slug: paste.slug,
+ values: valuesFrom(paste),
+ options: composerOptions(),
+ };
+};
+
+export const actions: Actions = {
+ default: async (event) => {
+ const paste = ownPaste(event);
+
+ const form = await event.request.formData();
+ if (!csrfOk(event, form.get("_csrf"))) formExpired();
+
+ const parsed = parseComposer(form);
+ if (parsed.error) {
+ // The slug isn't editable, so keep showing the real one
+ parsed.values.slug = paste.slug;
+ return fail(400, {
+ error: parsed.error,
+ values: parsed.values,
+ });
+ }
+
+ updatePaste(paste.slug, {
+ title: cleanText(parsed.values.title, 200),
+ body: parsed.values.body,
+ language: parsed.values.language,
+ theme: parsed.values.theme,
+ accent: parsed.accent,
+ unlisted: parsed.values.unlisted,
+ expiresAt: parsed.expiresAt,
+ });
+
+ redirect(303, `/${paste.slug}?m=paste-updated`);
+ },
+};
diff --git a/src/routes/[slug]/edit/+page.svelte b/src/routes/[slug]/edit/+page.svelte
new file mode 100644
index 0000000..20bc7f4
--- /dev/null
+++ b/src/routes/[slug]/edit/+page.svelte
@@ -0,0 +1,34 @@
+<!-- src/routes/[slug]/edit/+page.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 { siteName } from "#lib";
+ import Composer from "#lib/components/Composer.svelte";
+
+ let { data, form } = $props();
+</script>
+
+<svelte:head>
+ <title>Edit {data.slug} · {siteName}</title>
+ <meta name="robots" content="noindex" />
+</svelte:head>
+
+<div class="page">
+ <div class="page-head">
+ <p class="eyebrow">Pastebin</p>
+ <h1>Edit paste</h1>
+ </div>
+
+ <section class="panel">
+ <Composer
+ values={form?.values ?? data.values}
+ options={data.options}
+ csrf={data.csrf}
+ error={form?.error}
+ editing={data.slug}
+ />
+ </section>
+</div>
diff --git a/src/routes/[slug]/style.css/+server.ts b/src/routes/[slug]/style.css/+server.ts
new file mode 100644
index 0000000..cef8270
--- /dev/null
+++ b/src/routes/[slug]/style.css/+server.ts
@@ -0,0 +1,29 @@
+/* src/routes/[slug]/style.css/+server.ts
+ * 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.
+ */
+
+import type { RequestHandler } from "./$types";
+import { getPaste } from "#lib/server/db.ts";
+import { accentVars } from "#lib/server/colour.ts";
+import { renderPaste } from "#lib/server/highlight.ts";
+
+// A paste's own CSS: Shiki's token classes and its accent. Served as a file so
+// the page's CSP never has to allow inline styles
+export const GET: RequestHandler = async ({ params }) => {
+ const paste = getPaste(params.slug);
+ if (!paste) return new Response("/* not found */", { status: 404 });
+
+ const rendered = await renderPaste(paste);
+ const accent = paste.accent ? `body{${accentVars(paste.accent)}}` : "";
+ const sheet = [accent, rendered.css].filter(Boolean).join("\n");
+
+ return new Response(sheet, {
+ headers: {
+ "Content-Type": "text/css; charset=utf-8",
+ // The page links it with ?v=updated_at, so an edit is a new URL
+ "Cache-Control": "public, max-age=86400",
+ },
+ });
+};
diff --git a/src/routes/auth.tsx b/src/routes/auth.tsx
deleted file mode 100644
index 2adb1f3..0000000
--- a/src/routes/auth.tsx
+++ /dev/null
@@ -1,104 +0,0 @@
-/* src/routes/auth.tsx
- * 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.
- */
-
-import { Hono } from "hono";
-import { TTL, now, type AppEnv } from "../env";
-import { createLogin, takeLogin, upsertUser } from "../db";
-import { authorizeUrl, endSessionUrl, exchangeCode } from "../auth/oidc";
-import { csrfOk, endCurrentSession, startSession } from "../auth/session";
-import { pkce, randomToken, sha256Hex } from "../lib/crypto";
-import { form, safeReturn } from "../lib/http";
-import { message } from "../views/layout";
-
-export const auth = new Hono<AppEnv>();
-
-/**
- * Starts the OpenID Connect code flow against the Doughmination auth server.
- * The state, PKCE verifier and nonce live in this app's database rather than
- * in a cookie, so a reply that doesn't match a sign-in we started is rejected
- * without trusting anything the browser carried back.
- */
-auth.get("/auth/login", async (c) => {
- if (c.get("user")) return c.redirect(safeReturn(c.req.query("return_to")));
-
- const state = randomToken(24);
- const nonce = randomToken(24);
- const { verifier, challenge } = await pkce();
- const returnTo = safeReturn(c.req.query("return_to"));
-
- createLogin(await sha256Hex(state), verifier, nonce, returnTo, now() + TTL.pendingLogin);
-
- try {
- return c.redirect(await authorizeUrl(state, challenge, nonce));
- } catch (err) {
- console.error("[auth] could not reach the auth server:", err);
- return message(
- c,
- "Sign-in is unavailable",
- "The authentication server didn't answer. Pastes are still readable; try signing in again in a moment.",
- 502,
- );
- }
-});
-
-auth.get("/auth/callback", async (c) => {
- const query = c.req.query();
-
- // The auth server reports a refusal (e.g. the account isn't in an allowed
- // group) on the redirect rather than at the token endpoint.
- if (query.error) {
- const detail = query.error === "access_denied" ? "Your account isn't allowed to use this pastebin." : query.error;
- return message(c, "Sign-in refused", detail, 403);
- }
-
- if (!query.code || !query.state) {
- return message(c, "Incomplete sign-in", "That sign-in reply was missing its code or state.", 400);
- }
-
- const login = takeLogin(await sha256Hex(query.state));
- if (!login) {
- return message(
- c,
- "That sign-in expired",
- "Sign-ins are good for ten minutes and can only be used once. Start again from the sign-in button.",
- 400,
- );
- }
-
- let identity;
- try {
- identity = await exchangeCode(query.code, login.verifier, login.nonce);
- } catch (err) {
- console.error("[auth] code exchange failed:", err);
- return message(c, "Sign-in failed", "The authentication server wouldn't confirm that sign-in.", 502);
- }
-
- upsertUser(identity);
- await startSession(c, identity.id);
-
- const separator = login.return_to.includes("?") ? "&" : "?";
- return c.redirect(`${login.return_to}${separator}m=signed-in`);
-});
-
-auth.post("/auth/logout", async (c) => {
- const body = await form(c);
- if (!csrfOk(c, body._csrf)) return c.text("That form expired. Go back and try again.", 403);
-
- await endCurrentSession(c);
-
- // Ending the session here leaves the auth server's own session alone, so
- // offer to close that too rather than deciding for the user.
- const single = body.everywhere === "1";
- if (single) {
- try {
- const url = await endSessionUrl();
- if (url) return c.redirect(url);
- } catch (err) {
- console.error("[auth] end-session lookup failed:", err);
- }
- }
- return c.redirect("/?m=signed-out");
-});
diff --git a/src/routes/auth/callback/+page.server.ts b/src/routes/auth/callback/+page.server.ts
new file mode 100644
index 0000000..79138d3
--- /dev/null
+++ b/src/routes/auth/callback/+page.server.ts
@@ -0,0 +1,60 @@
+/* src/routes/auth/callback/+page.server.ts
+ * 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.
+ */
+
+import { error, redirect } from "@sveltejs/kit";
+import type { PageServerLoad } from "./$types";
+import { takeLogin, upsertUser } from "#lib/server/db.ts";
+import { exchangeCode, type Identity } from "#lib/server/oidc.ts";
+import { startSession } from "#lib/server/session.ts";
+import { sha256Hex } from "#lib/server/crypto.ts";
+
+export const load: PageServerLoad = async ({ url, cookies }) => {
+ const query = url.searchParams;
+
+ // The auth server reports a refusal (e.g. the account isn't in an allowed
+ // group) on the redirect rather than at the token endpoint
+ const refusal = query.get("error");
+ if (refusal) {
+ error(403, {
+ title: "Sign-in refused",
+ message: refusal === "access_denied" ? "Your account isn't allowed to use this pastebin." : refusal,
+ });
+ }
+
+ const code = query.get("code");
+ const state = query.get("state");
+ if (!code || !state) {
+ error(400, {
+ title: "Incomplete sign-in",
+ message: "That sign-in reply was missing its code or state.",
+ });
+ }
+
+ const login = takeLogin(await sha256Hex(state));
+ if (!login) {
+ error(400, {
+ title: "That sign-in expired",
+ message: "Sign-ins are good for ten minutes and can only be used once. Start again from the sign-in button.",
+ });
+ }
+
+ let identity: Identity;
+ try {
+ identity = await exchangeCode(code, login.verifier, login.nonce);
+ } catch (err) {
+ console.error("[auth] code exchange failed:", err);
+ error(502, {
+ title: "Sign-in failed",
+ message: "The authentication server wouldn't confirm that sign-in.",
+ });
+ }
+
+ upsertUser(identity);
+ await startSession(cookies, identity.id);
+
+ const separator = login.return_to.includes("?") ? "&" : "?";
+ redirect(303, `${login.return_to}${separator}m=signed-in`);
+};
diff --git a/src/routes/auth/callback/+page.svelte b/src/routes/auth/callback/+page.svelte
new file mode 100644
index 0000000..8e75e61
--- /dev/null
+++ b/src/routes/auth/callback/+page.svelte
@@ -0,0 +1,7 @@
+<!-- src/routes/auth/callback/+page.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.
+-->
+
+<!-- Never shown: the server load always redirects or errors -->
diff --git a/src/routes/auth/login/+page.server.ts b/src/routes/auth/login/+page.server.ts
new file mode 100644
index 0000000..43de4d5
--- /dev/null
+++ b/src/routes/auth/login/+page.server.ts
@@ -0,0 +1,45 @@
+/* src/routes/auth/login/+page.server.ts
+ * 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.
+ */
+
+import { error, redirect } from "@sveltejs/kit";
+import type { PageServerLoad } from "./$types";
+import { TTL, config, now } from "#lib/server/env.ts";
+import { createLogin } from "#lib/server/db.ts";
+import { authorizeUrl } from "#lib/server/oidc.ts";
+import { pkce, randomToken, sha256Hex } from "#lib/server/crypto.ts";
+import { safeReturn } from "#lib/server/validate.ts";
+
+/**
+ * Starts the OpenID Connect code flow against the Doughmination auth server.
+ * The state, PKCE verifier and nonce live in this app's database rather than
+ * in a cookie, so a reply that doesn't match a sign-in we started is rejected
+ * without trusting anything the browser carried back.
+ */
+export const load: PageServerLoad = async ({ locals, url }) => {
+ const returnTo = safeReturn(url.searchParams.get("return_to"));
+ if (locals.user) redirect(303, returnTo);
+
+ const state = randomToken(24);
+ const nonce = randomToken(24);
+ const { verifier, challenge } = await pkce();
+
+ createLogin(await sha256Hex(state), verifier, nonce, returnTo, now() + TTL.pendingLogin);
+
+ let target: string;
+ try {
+ target = await authorizeUrl(state, challenge, nonce);
+ } catch (err) {
+ console.error("[auth] could not reach the auth server:", err);
+ error(502, {
+ title: "Sign-in is unavailable",
+ message: "The authentication server didn't answer. Pastes are still readable; try signing in again in a moment.",
+ });
+ }
+ // Off-site, but only ever to the auth server
+ redirect(303, target, {
+ external: [new URL(config.issuer).origin],
+ });
+};
diff --git a/src/routes/auth/login/+page.svelte b/src/routes/auth/login/+page.svelte
new file mode 100644
index 0000000..0fa1997
--- /dev/null
+++ b/src/routes/auth/login/+page.svelte
@@ -0,0 +1,7 @@
+<!-- src/routes/auth/login/+page.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.
+-->
+
+<!-- Never shown: the server load always redirects or errors -->
diff --git a/src/routes/auth/logout/+page.server.ts b/src/routes/auth/logout/+page.server.ts
new file mode 100644
index 0000000..d42787d
--- /dev/null
+++ b/src/routes/auth/logout/+page.server.ts
@@ -0,0 +1,42 @@
+/* src/routes/auth/logout/+page.server.ts
+ * 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.
+ */
+
+import { redirect } from "@sveltejs/kit";
+import type { Actions, PageServerLoad } from "./$types";
+import { config } from "#lib/server/env.ts";
+import { endSessionUrl } from "#lib/server/oidc.ts";
+import { csrfOk, endCurrentSession } from "#lib/server/session.ts";
+import { formExpired } from "#lib/server/compose.ts";
+
+// Signing out is a POST; a stray GET just goes home
+export const load: PageServerLoad = () => redirect(303, "/");
+
+export const actions: Actions = {
+ default: async (event) => {
+ const form = await event.request.formData();
+ if (!csrfOk(event, form.get("_csrf"))) formExpired();
+
+ endCurrentSession(event);
+
+ // Ending the session here leaves the auth server's own session alone, so
+ // only close that too when asked
+ if (form.get("everywhere") === "1") {
+ let url: string | null = null;
+ try {
+ url = await endSessionUrl();
+ } catch (err) {
+ console.error("[auth] end-session lookup failed:", err);
+ }
+ if (url) {
+ redirect(303, url, {
+ external: [new URL(config.issuer).origin],
+ });
+ }
+ }
+
+ redirect(303, "/?m=signed-out");
+ },
+};
diff --git a/src/routes/auth/logout/+page.svelte b/src/routes/auth/logout/+page.svelte
new file mode 100644
index 0000000..9225b09
--- /dev/null
+++ b/src/routes/auth/logout/+page.svelte
@@ -0,0 +1,7 @@
+<!-- src/routes/auth/logout/+page.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.
+-->
+
+<!-- Never shown: the server load always redirects or errors -->
diff --git a/src/routes/dl/[slug]/+server.ts b/src/routes/dl/[slug]/+server.ts
new file mode 100644
index 0000000..1c52956
--- /dev/null
+++ b/src/routes/dl/[slug]/+server.ts
@@ -0,0 +1,23 @@
+/* src/routes/dl/[slug]/+server.ts
+ * 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.
+ */
+
+import type { RequestHandler } from "./$types";
+import { getPaste } from "#lib/server/db.ts";
+import { extensionFor } from "#lib/server/highlight.ts";
+
+export const GET: RequestHandler = ({ params }) => {
+ const paste = getPaste(params.slug);
+ if (!paste) return new Response("Not found", { status: 404 });
+
+ const name = `${paste.slug}.${extensionFor(paste.language)}`.replace(/[^\w.-]/g, "_");
+ return new Response(paste.body, {
+ headers: {
+ "Content-Type": "application/octet-stream",
+ "Content-Disposition": `attachment; filename="${name}"`,
+ "Content-Security-Policy": "default-src 'none'; sandbox",
+ },
+ });
+};
diff --git a/src/routes/health/+server.ts b/src/routes/health/+server.ts
new file mode 100644
index 0000000..460e990
--- /dev/null
+++ b/src/routes/health/+server.ts
@@ -0,0 +1,10 @@
+/* src/routes/health/+server.ts
+ * 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.
+ */
+
+import { json } from "@sveltejs/kit";
+import type { RequestHandler } from "./$types";
+
+export const GET: RequestHandler = () => json({ ok: true });
diff --git a/src/routes/mine/+page.server.ts b/src/routes/mine/+page.server.ts
new file mode 100644
index 0000000..e70251b
--- /dev/null
+++ b/src/routes/mine/+page.server.ts
@@ -0,0 +1,23 @@
+/* src/routes/mine/+page.server.ts
+ * 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.
+ */
+
+import { redirect } from "@sveltejs/kit";
+import type { PageServerLoad } from "./$types";
+import { countPastesByAuthor, listPastesByAuthor } from "#lib/server/db.ts";
+import { PER_PAGE, pageNumber, toRow } from "#lib/server/listing.ts";
+
+export const load: PageServerLoad = ({ locals, url }) => {
+ const user = locals.user;
+ if (!user) redirect(303, "/auth/login?return_to=%2Fmine");
+
+ const page = pageNumber(url);
+ return {
+ page,
+ total: countPastesByAuthor(user.id),
+ perPage: PER_PAGE,
+ pastes: listPastesByAuthor(user.id, PER_PAGE, (page - 1) * PER_PAGE).map(toRow),
+ };
+};
diff --git a/src/routes/mine/+page.svelte b/src/routes/mine/+page.svelte
new file mode 100644
index 0000000..64488c2
--- /dev/null
+++ b/src/routes/mine/+page.svelte
@@ -0,0 +1,34 @@
+<!-- src/routes/mine/+page.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 { siteName } from "#lib";
+ import Flash from "#lib/components/Flash.svelte";
+ import Pager from "#lib/components/Pager.svelte";
+ import PasteRows from "#lib/components/PasteRows.svelte";
+
+ let { data } = $props();
+</script>
+
+<svelte:head>
+ <title>Your pastes · {siteName}</title>
+ <meta name="robots" content="noindex" />
+</svelte:head>
+
+<div class="page">
+ <div class="page-head">
+ <p class="eyebrow">Pastebin</p>
+ <h1>Your pastes</h1>
+ <p class="muted">Everything you've published, unlisted ones included.</p>
+ </div>
+
+ <Flash />
+
+ <section class="panel">
+ <PasteRows pastes={data.pastes} showAuthor={false} empty="You haven't published anything yet." />
+ <Pager path="/mine" page={data.page} total={data.total} perPage={data.perPage} />
+ </section>
+</div>
diff --git a/src/routes/new/+page.server.ts b/src/routes/new/+page.server.ts
new file mode 100644
index 0000000..9cf5aac
--- /dev/null
+++ b/src/routes/new/+page.server.ts
@@ -0,0 +1,91 @@
+/* src/routes/new/+page.server.ts
+ * 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.
+ */
+
+import { error, fail, redirect } from "@sveltejs/kit";
+import type { Actions, PageServerLoad } from "./$types";
+import { now } from "#lib/server/env.ts";
+import { countRecentByAuthor, createPaste, slugTaken } from "#lib/server/db.ts";
+import { csrfOk } from "#lib/server/session.ts";
+import { cleanText, slugProblem } from "#lib/server/validate.ts";
+import {
+ HOURLY_LIMIT,
+ blankValues,
+ composerOptions,
+ formExpired,
+ freeSlug,
+ parseComposer,
+} from "#lib/server/compose.ts";
+
+export const load: PageServerLoad = ({ locals }) => {
+ if (!locals.user) redirect(303, "/auth/login?return_to=%2Fnew&m=sign-in-needed");
+
+ return {
+ values: blankValues(),
+ options: composerOptions(),
+ };
+};
+
+export const actions: Actions = {
+ default: async (event) => {
+ const user = event.locals.user;
+ if (!user) {
+ error(401, {
+ title: "Sign in first",
+ message: "Only signed-in accounts can publish pastes.",
+ });
+ }
+
+ const form = await event.request.formData();
+ if (!csrfOk(event, form.get("_csrf"))) formExpired();
+
+ if (countRecentByAuthor(user.id, now() - 3600) >= HOURLY_LIMIT) {
+ error(429, {
+ title: "Slow down",
+ message: `That's ${HOURLY_LIMIT} pastes in an hour. Try again later.`,
+ });
+ }
+
+ const parsed = parseComposer(form);
+ const reject = (message: string) =>
+ fail(400, {
+ error: message,
+ values: parsed.values,
+ });
+
+ if (parsed.error) return reject(parsed.error);
+
+ let slug: string;
+ if (parsed.values.slug) {
+ slug = parsed.values.slug;
+ const fault = slugProblem(slug);
+ if (fault) return reject(fault);
+ if (slugTaken(slug)) return reject(`The slug "${slug}" is already taken.`);
+ } else {
+ const generated = freeSlug();
+ if (!generated) {
+ error(503, {
+ title: "Couldn't allocate an address",
+ message: "Please try publishing again.",
+ });
+ }
+ slug = generated;
+ }
+
+ createPaste({
+ slug,
+ authorId: user.id,
+ title: cleanText(parsed.values.title, 200),
+ body: parsed.values.body,
+ language: parsed.values.language,
+ theme: parsed.values.theme,
+ accent: parsed.accent,
+ unlisted: parsed.values.unlisted,
+ expiresAt: parsed.expiresAt,
+ });
+
+ redirect(303, `/${slug}?m=paste-created`);
+ },
+};
diff --git a/src/routes/new/+page.svelte b/src/routes/new/+page.svelte
new file mode 100644
index 0000000..e45237d
--- /dev/null
+++ b/src/routes/new/+page.svelte
@@ -0,0 +1,33 @@
+<!-- src/routes/new/+page.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 { siteName } from "#lib";
+ import Composer from "#lib/components/Composer.svelte";
+
+ let { data, form } = $props();
+</script>
+
+<svelte:head>
+ <title>New paste · {siteName}</title>
+ <meta name="robots" content="noindex" />
+</svelte:head>
+
+<div class="page">
+ <div class="page-head">
+ <p class="eyebrow">Pastebin</p>
+ <h1>New paste</h1>
+ </div>
+
+ <section class="panel">
+ <Composer
+ values={form?.values ?? data.values}
+ options={data.options}
+ csrf={data.csrf}
+ error={form?.error}
+ />
+ </section>
+</div>
diff --git a/src/routes/pastes.tsx b/src/routes/pastes.tsx
deleted file mode 100644
index 7b126b5..0000000
--- a/src/routes/pastes.tsx
+++ /dev/null
@@ -1,416 +0,0 @@
-/* src/routes/pastes.tsx
- * 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.
- */
-
-import { Hono } from "hono";
-import { config, now, type AppContext, type AppEnv } from "../env";
-import {
- countPastes,
- countPastesByAuthor,
- countRecentByAuthor,
- createPaste,
- deletePaste,
- getPaste,
- listPastes,
- listPastesByAuthor,
- slugTaken,
- updatePaste,
- type PasteWithAuthor,
-} from "../db";
-import { csrfOk } from "../auth/session";
-import { randomSlug } from "../lib/crypto";
-import { form } from "../lib/http";
-import { ACCENT_PRESETS, accentVars, normaliseHex } from "../lib/colour";
-import {
- cleanText,
- expiresAtFrom,
- expiryIdFrom,
- expiryProblem,
- normaliseBody,
- normaliseSlug,
- slugProblem,
-} from "../lib/validate";
-import {
- DEFAULT_THEME,
- extensionFor,
- isLanguage,
- isTheme,
- render as highlight,
- shouldNumber,
- themeIsLight,
-} from "../highlight";
-import { check as checkJpml } from "../jpml";
-import { message, render } from "../views/layout";
-import { Composer, PasteRows, PasteView, type ComposerValues } from "../views/pastes";
-import { Flash, Pager } from "../views/ui";
-
-export const pastes = new Hono<AppEnv>();
-
-const PER_PAGE = 25;
-
-/** Pastes one account may publish per hour, so a stuck script can't fill the disk. */
-const HOURLY_LIMIT = 60;
-
-function pageNumber(c: AppContext): number {
- const raw = Number(c.req.query("page") ?? "1");
- return Number.isFinite(raw) && raw >= 1 ? Math.floor(raw) : 1;
-}
-
-// --- listings -------------------------------------------------------------------------
-
-pastes.get("/", (c) => {
- const page = pageNumber(c);
- const total = countPastes();
- const rows = listPastes(PER_PAGE, (page - 1) * PER_PAGE);
-
- return render(
- c,
- { title: "Recent pastes", description: `Public pastes on ${config.siteName}.` },
- <>
- <Flash code={c.req.query("m")} />
- <div class="card">
- <h1>Recent pastes</h1>
- <p class="muted">
- Anyone can read what's here. {c.get("user") ? "Publish one from the New paste button." : "Sign in to publish one."}
- </p>
- <PasteRows pastes={rows} empty="Nothing published yet." />
- <Pager path="/" page={page} total={total} perPage={PER_PAGE} />
- </div>
- </>,
- );
-});
-
-pastes.get("/mine", async (c) => {
- const user = c.get("user");
- if (!user) return c.redirect("/auth/login?return_to=%2Fmine");
-
- const page = pageNumber(c);
- const total = countPastesByAuthor(user.id);
- const rows = listPastesByAuthor(user.id, PER_PAGE, (page - 1) * PER_PAGE);
-
- return render(
- c,
- { title: "Your pastes", noindex: true },
- <>
- <Flash code={c.req.query("m")} />
- <div class="card">
- <h1>Your pastes</h1>
- <p class="muted">Everything you've published, unlisted ones included.</p>
- <PasteRows pastes={rows} showAuthor={false} empty="You haven't published anything yet." />
- <Pager path="/mine" page={page} total={total} perPage={PER_PAGE} />
- </div>
- </>,
- );
-});
-
-// --- composing -------------------------------------------------------------------------
-
-function blankValues(): ComposerValues {
- return {
- title: "",
- slug: "",
- body: "",
- language: "text",
- theme: DEFAULT_THEME,
- accentChoice: "none",
- accentCustom: "#9c1f34",
- expiry: "never",
- unlisted: false,
- };
-}
-
-/** Works out which accent control an existing paste's stored colour came from. */
-function valuesFrom(paste: PasteWithAuthor): ComposerValues {
- const preset = paste.accent ? ACCENT_PRESETS.find((p) => p.hex === paste.accent) : undefined;
- return {
- title: paste.title ?? "",
- slug: paste.slug,
- body: paste.body,
- language: paste.language,
- theme: paste.theme,
- accentChoice: paste.accent === null ? "none" : (preset?.id ?? "custom"),
- accentCustom: paste.accent ?? "#9c1f34",
- expiry: expiryIdFrom(paste.expires_at),
- unlisted: paste.unlisted === 1,
- };
-}
-
-interface Parsed {
- values: ComposerValues;
- error: string | null;
- /** Filled in only when `error` is null. */
- accent: string | null;
- expiresAt: number | null;
-}
-
-/**
- * Reads the composer form back into validated fields. Everything the user
- * typed survives on the returned `values` so a rejected submission can be
- * re-rendered without losing the paste.
- */
-function parseComposer(body: Record<string, string>): Parsed {
- const accentChoice = body.accent_choice ?? "none";
- const accentCustom = normaliseHex(body.accent_custom) ?? "#9c1f34";
-
- const values: ComposerValues = {
- title: (body.title ?? "").trim().slice(0, 200),
- slug: normaliseSlug(body.slug),
- body: normaliseBody(body.body),
- language: body.language ?? "text",
- theme: body.theme ?? DEFAULT_THEME,
- accentChoice,
- accentCustom,
- expiry: body.expiry ?? "never",
- unlisted: body.unlisted === "1",
- };
-
- const fail = (error: string): Parsed => ({ values, error, accent: null, expiresAt: null });
-
- if (!values.body) return fail("A paste needs some content.");
- const size = Buffer.byteLength(values.body, "utf8");
- if (size > config.maxBodyBytes) {
- return fail(`That paste is ${Math.round(size / 1024)} KB; the limit is ${Math.round(config.maxBodyBytes / 1024)} KB.`);
- }
-
- if (!isLanguage(values.language)) return fail("That isn't one of the languages on offer.");
- if (!isTheme(values.theme)) return fail("That isn't one of the highlight themes on offer.");
-
- const expiryFault = expiryProblem(values.expiry);
- if (expiryFault) return fail(expiryFault);
-
- let accent: string | null = null;
- if (accentChoice === "custom") {
- const hex = normaliseHex(body.accent_custom);
- if (!hex) return fail("That accent colour isn't a valid hex colour.");
- accent = hex;
- } else if (accentChoice !== "none") {
- const preset = ACCENT_PRESETS.find((p) => p.id === accentChoice);
- if (!preset) return fail("That isn't one of the accent colours on offer.");
- accent = preset.hex;
- }
-
- return { values, error: null, accent, expiresAt: expiresAtFrom(values.expiry) };
-}
-
-pastes.get("/new", async (c) => {
- const user = c.get("user");
- if (!user) return c.redirect("/auth/login?return_to=%2Fnew&m=sign-in-needed");
-
- return render(
- c,
- { title: "New paste", page: "composer", noindex: true },
- <div class="card">
- <h1>New paste</h1>
- <Composer values={blankValues()} csrf={c.get("session")!.csrf} maxBytes={config.maxBodyBytes} />
- </div>,
- );
-});
-
-pastes.post("/new", async (c) => {
- const user = c.get("user");
- if (!user) return message(c, "Sign in first", "Only signed-in accounts can publish pastes.", 401);
-
- const body = await form(c);
- if (!csrfOk(c, body._csrf)) return c.text("That form expired. Go back and try again.", 403);
-
- if (countRecentByAuthor(user.id, now() - 3600) >= HOURLY_LIMIT) {
- return message(c, "Slow down", `That's ${HOURLY_LIMIT} pastes in an hour. Try again later.`, 429);
- }
-
- const parsed = parseComposer(body);
- const reject = (error: string) =>
- render(
- c,
- { title: "New paste", page: "composer", status: 400, noindex: true },
- <div class="card">
- <h1>New paste</h1>
- <Composer values={parsed.values} csrf={c.get("session")!.csrf} error={error} maxBytes={config.maxBodyBytes} />
- </div>,
- );
-
- if (parsed.error) return reject(parsed.error);
-
- let slug: string;
- if (parsed.values.slug) {
- slug = parsed.values.slug;
- const fault = slugProblem(slug);
- if (fault) return reject(fault);
- if (slugTaken(slug)) return reject(`The slug "${slug}" is already taken.`);
- } else {
- const generated = freeSlug();
- if (!generated) return message(c, "Couldn't allocate an address", "Please try publishing again.", 503);
- slug = generated;
- }
-
- createPaste({
- slug,
- authorId: user.id,
- title: cleanText(parsed.values.title, 200),
- body: parsed.values.body,
- language: parsed.values.language,
- theme: parsed.values.theme,
- accent: parsed.accent,
- unlisted: parsed.values.unlisted,
- expiresAt: parsed.expiresAt,
- });
-
- return c.redirect(`/${slug}?m=paste-created`);
-});
-
-/** Generated slugs collide vanishingly rarely; a few tries removes the doubt. */
-function freeSlug(): string | null {
- for (let attempt = 0; attempt < 8; attempt++) {
- const slug = randomSlug(attempt < 5 ? 8 : 12);
- if (!slugTaken(slug)) return slug;
- }
- return null;
-}
-
-// --- reading -----------------------------------------------------------------------------
-
-pastes.get("/raw/:slug", (c) => {
- const paste = getPaste(c.req.param("slug"));
- if (!paste) return c.text("Not found", 404);
-
- c.header("Content-Type", "text/plain; charset=utf-8");
- c.header("X-Content-Type-Options", "nosniff");
- // A paste is arbitrary text from another account, so it is never allowed to
- // execute as a document on this origin.
- c.header("Content-Disposition", "inline");
- c.header("Content-Security-Policy", "default-src 'none'; sandbox");
- return c.body(paste.body);
-});
-
-pastes.get("/dl/:slug", (c) => {
- const paste = getPaste(c.req.param("slug"));
- if (!paste) return c.text("Not found", 404);
-
- const name = `${paste.slug}.${extensionFor(paste.language)}`;
- c.header("Content-Type", "application/octet-stream");
- c.header("X-Content-Type-Options", "nosniff");
- c.header("Content-Disposition", `attachment; filename="${name.replace(/[^\w.-]/g, "_")}"`);
- return c.body(paste.body);
-});
-
-pastes.get("/:slug", async (c) => {
- const paste = getPaste(c.req.param("slug"));
- if (!paste) {
- return message(c, "No such paste", "It may have expired, been deleted, or never existed.", 404);
- }
-
- const user = c.get("user");
- const rendered = await highlight(paste.body, paste.language, paste.theme);
- const jpml = paste.language === "jpml" ? checkJpml(paste.body) : null;
-
- return render(
- c,
- {
- title: paste.title ?? paste.slug,
- page: "paste",
- full: true,
- css: rendered.css,
- accentVars: paste.accent ? accentVars(paste.accent) : undefined,
- noindex: paste.unlisted === 1,
- description: paste.title ?? `A paste by ${paste.author_username}.`,
- },
- <>
- <Flash code={c.req.query("m")} />
- <PasteView
- paste={paste}
- html={rendered.html}
- lines={rendered.lines}
- numbered={shouldNumber(rendered.lines)}
- highlighted={rendered.highlighted}
- light={themeIsLight(paste.theme)}
- jpml={jpml}
- isOwner={user?.id === paste.author_id}
- csrf={c.get("session")?.csrf ?? ""}
- size={Buffer.byteLength(paste.body, "utf8")}
- />
- </>,
- );
-});
-
-// --- editing -------------------------------------------------------------------------------
-
-/** Resolves a paste the signed-in account is allowed to change. */
-async function ownPaste(c: AppContext): Promise<PasteWithAuthor | Response> {
- const user = c.get("user");
- const paste = getPaste(c.req.param("slug") ?? "");
- if (!paste) return message(c, "No such paste", "It may have expired, been deleted, or never existed.", 404);
- if (!user) return message(c, "Sign in first", "Only the author can change a paste.", 401);
- if (paste.author_id !== user.id) return message(c, "Not yours", "Only the author can change this paste.", 403);
- return paste;
-}
-
-pastes.get("/:slug/edit", async (c) => {
- const found = await ownPaste(c);
- if (found instanceof Response) return found;
-
- return render(
- c,
- { title: `Edit ${found.slug}`, page: "composer", noindex: true },
- <div class="card">
- <h1>Edit paste</h1>
- <Composer
- values={valuesFrom(found)}
- csrf={c.get("session")!.csrf}
- editing={found.slug}
- maxBytes={config.maxBodyBytes}
- />
- </div>,
- );
-});
-
-pastes.post("/:slug/edit", async (c) => {
- const found = await ownPaste(c);
- if (found instanceof Response) return found;
-
- const body = await form(c);
- if (!csrfOk(c, body._csrf)) return c.text("That form expired. Go back and try again.", 403);
-
- const parsed = parseComposer(body);
- if (parsed.error) {
- // The slug isn't editable, so keep showing the real one.
- parsed.values.slug = found.slug;
- return render(
- c,
- { title: `Edit ${found.slug}`, page: "composer", status: 400, noindex: true },
- <div class="card">
- <h1>Edit paste</h1>
- <Composer
- values={parsed.values}
- csrf={c.get("session")!.csrf}
- editing={found.slug}
- error={parsed.error}
- maxBytes={config.maxBodyBytes}
- />
- </div>,
- );
- }
-
- updatePaste(found.slug, {
- title: cleanText(parsed.values.title, 200),
- body: parsed.values.body,
- language: parsed.values.language,
- theme: parsed.values.theme,
- accent: parsed.accent,
- unlisted: parsed.values.unlisted,
- expiresAt: parsed.expiresAt,
- });
-
- return c.redirect(`/${found.slug}?m=paste-updated`);
-});
-
-pastes.post("/:slug/delete", async (c) => {
- const found = await ownPaste(c);
- if (found instanceof Response) return found;
-
- const body = await form(c);
- if (!csrfOk(c, body._csrf)) return c.text("That form expired. Go back and try again.", 403);
-
- deletePaste(found.slug);
- return c.redirect("/mine?m=paste-deleted");
-});
diff --git a/src/routes/raw/[slug]/+server.ts b/src/routes/raw/[slug]/+server.ts
new file mode 100644
index 0000000..dd7fcb7
--- /dev/null
+++ b/src/routes/raw/[slug]/+server.ts
@@ -0,0 +1,23 @@
+/* src/routes/raw/[slug]/+server.ts
+ * 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.
+ */
+
+import type { RequestHandler } from "./$types";
+import { getPaste } from "#lib/server/db.ts";
+
+export const GET: RequestHandler = ({ params }) => {
+ const paste = getPaste(params.slug);
+ if (!paste) return new Response("Not found", { status: 404 });
+
+ // A paste is arbitrary text from another account, so it is never allowed to
+ // execute as a document on this origin
+ return new Response(paste.body, {
+ headers: {
+ "Content-Type": "text/plain; charset=utf-8",
+ "Content-Disposition": "inline",
+ "Content-Security-Policy": "default-src 'none'; sandbox",
+ },
+ });
+};
diff --git a/src/routes/robots.txt/+server.ts b/src/routes/robots.txt/+server.ts
new file mode 100644
index 0000000..eb771f5
--- /dev/null
+++ b/src/routes/robots.txt/+server.ts
@@ -0,0 +1,15 @@
+/* src/routes/robots.txt/+server.ts
+ * 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.
+ */
+
+import type { RequestHandler } from "./$types";
+
+export const GET: RequestHandler = () =>
+ new Response("User-agent: *\nDisallow: /new\nDisallow: /mine\nDisallow: /auth/\n", {
+ headers: {
+ "Content-Type": "text/plain; charset=utf-8",
+ "Cache-Control": "public, max-age=3600",
+ },
+ });
diff --git a/src/views/layout.tsx b/src/views/layout.tsx
deleted file mode 100644
index c975edb..0000000
--- a/src/views/layout.tsx
+++ /dev/null
@@ -1,115 +0,0 @@
-/* src/views/layout.tsx
- * 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.
- */
-
-import { raw } from "hono/html";
-import type { Child } from "hono/jsx";
-import type { ContentfulStatusCode } from "hono/utils/http-status";
-import { config, type AppContext } from "../env";
-
-export interface PageOptions {
- title: string;
- /** Picks the behaviour in /static/app.js. */
- page?: string;
- /** Centered card layout for short pages. */
- narrow?: boolean;
- /** Full-bleed layout for reading code. */
- full?: boolean;
- status?: ContentfulStatusCode;
- /** Extra CSS for this response only, emitted under the page's CSP nonce. */
- css?: string;
- /** Accent overrides from a paste, applied to <body>. */
- accentVars?: string;
- description?: string;
- /** Set on paste pages so a stale copy is never served after an edit. */
- noindex?: boolean;
-}
-
-export async function render(c: AppContext, opts: PageOptions, body: Child): Promise<Response> {
- const user = c.get("user");
- const session = c.get("session");
- const nonce = c.get("nonce");
-
- const layout = opts.full ? "full" : opts.narrow ? "narrow" : "wide";
-
- // Shiki's token colours and a paste's accent both arrive as CSS text. They
- // go in one nonced <style> rather than on inline style attributes, which a
- // nonce cannot cover — see highlight.ts.
- const sheet = [opts.accentVars ? `body{${opts.accentVars}}` : "", opts.css ?? ""].filter(Boolean).join("\n");
-
- const html = (
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1" />
- <meta name="color-scheme" content="dark" />
- {opts.noindex && <meta name="robots" content="noindex" />}
- <title>{`${opts.title} · ${config.siteName}`}</title>
- {opts.description && <meta name="description" content={opts.description} />}
- <link rel="icon" type="image/svg+xml" href="/static/favicon.svg" />
- <link rel="stylesheet" href="/static/style.css" />
- <script src="/static/app.js" defer></script>
- {sheet && raw(`<style nonce="${nonce}">${sheet}</style>`)}
- </head>
- <body data-page={opts.page ?? ""} data-csrf={session?.csrf ?? ""}>
- <header class="topbar">
- <a class="brand" href="/">
- {config.siteName}
- </a>
- <nav>
- <a class="btn small" href="/">
- Recent
- </a>
- {user ? (
- <>
- <a class="btn small" href="/mine">
- Mine
- </a>
- <a class="btn small primary" href="/new">
- New paste
- </a>
- <form method="post" action="/auth/logout" class="inline">
- <input type="hidden" name="_csrf" value={session?.csrf ?? ""} />
- <button type="submit" class="small" title={`Signed in as ${user.username}`}>
- Sign out
- </button>
- </form>
- </>
- ) : (
- <a class="btn small primary" href={`/auth/login?return_to=${encodeURIComponent(currentPath(c))}`}>
- Sign in
- </a>
- )}
- </nav>
- </header>
- <main class={layout}>{body}</main>
- </body>
- </html>
- );
-
- return c.html(`<!doctype html>${await html}`, opts.status ?? 200);
-}
-
-function currentPath(c: AppContext): string {
- const url = new URL(c.req.url);
- return url.pathname + url.search;
-}
-
-/** Small standalone page for 404s and refusals. */
-export function message(c: AppContext, title: string, text: string, status: ContentfulStatusCode = 400) {
- return render(
- c,
- { title, narrow: true, status },
- <div class="card">
- <h1>{title}</h1>
- <p class="muted">{text}</p>
- <p>
- <a class="btn" href="/">
- Back to recent pastes
- </a>
- </p>
- </div>,
- );
-}
diff --git a/src/views/pastes.tsx b/src/views/pastes.tsx
deleted file mode 100644
index 651b02c..0000000
--- a/src/views/pastes.tsx
+++ /dev/null
@@ -1,325 +0,0 @@
-/* src/views/pastes.tsx
- * 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.
- */
-
-import { raw } from "hono/html";
-import type { PasteWithAuthor } from "../db";
-import { LANGUAGES, THEMES, languageLabel } from "../highlight";
-import { ACCENT_PRESETS } from "../lib/colour";
-import { EXPIRY_OPTIONS } from "../lib/validate";
-import type { JpmlCheck } from "../jpml";
-import { Csrf, ErrorNote, bytes, date, relative } from "./ui";
-
-export interface ComposerValues {
- title: string;
- slug: string;
- body: string;
- language: string;
- theme: string;
- accentChoice: string;
- accentCustom: string;
- expiry: string;
- unlisted: boolean;
-}
-
-export interface ComposerProps {
- values: ComposerValues;
- csrf: string;
- error?: string | null;
- /** Present when editing: the slug is already spent and can't move. */
- editing?: string;
- maxBytes: number;
-}
-
-export function Composer(props: ComposerProps) {
- const { values, editing } = props;
- const action = editing ? `/${editing}/edit` : "/new";
-
- return (
- <form method="post" action={action} class="composer stack" data-max-bytes={String(props.maxBytes)}>
- <Csrf token={props.csrf} />
- <ErrorNote error={props.error} />
-
- <div class="grid2">
- <label class="field">
- <span>Title</span>
- <input type="text" name="title" value={values.title} maxlength={200} placeholder="Optional" autofocus />
- </label>
-
- <label class="field">
- <span>Slug</span>
- {editing ? (
- <input type="text" value={editing} readonly disabled />
- ) : (
- <input
- type="text"
- name="slug"
- value={values.slug}
- maxlength={64}
- placeholder="Optional — a short one is generated"
- pattern="[A-Za-z0-9_-]{3,64}"
- autocapitalize="off"
- autocorrect="off"
- spellcheck={false}
- />
- )}
- <small class="muted">
- {editing ? "A paste keeps its address for good." : "Becomes the address: /your-slug"}
- </small>
- </label>
- </div>
-
- <label class="field">
- <span>Content</span>
- <textarea
- name="body"
- rows={22}
- required
- spellcheck={false}
- autocapitalize="off"
- autocorrect="off"
- placeholder="Paste away."
- >
- {values.body}
- </textarea>
- <small class="muted">
- <span data-counter>0 B</span> of {bytes(props.maxBytes)}
- </small>
- </label>
-
- <div class="grid2">
- <label class="field">
- <span>Language</span>
- <select name="language">
- {LANGUAGES.map((lang) => (
- <option value={lang.id} selected={lang.id === values.language}>
- {lang.label}
- </option>
- ))}
- </select>
- </label>
-
- <label class="field">
- <span>Highlight theme</span>
- <select name="theme">
- {THEMES.map((theme) => (
- <option value={theme.id} selected={theme.id === values.theme}>
- {theme.label}
- </option>
- ))}
- </select>
- </label>
- </div>
-
- <fieldset class="field">
- <legend>Accent colour</legend>
- <p class="muted small">Re-tints this paste's page. Everything else keeps the site's own colours.</p>
- <div class="swatches">
- <label class={`swatch swatch-none${values.accentChoice === "none" ? " on" : ""}`} title="Site default">
- <input type="radio" name="accent_choice" value="none" checked={values.accentChoice === "none"} />
- <span class="swatch-dot" aria-hidden="true" />
- <span class="swatch-label">Default</span>
- </label>
-
- {ACCENT_PRESETS.map((preset) => (
- <label
- class={`swatch swatch-${preset.id}${values.accentChoice === preset.id ? " on" : ""}`}
- title={preset.label}
- >
- <input type="radio" name="accent_choice" value={preset.id} checked={values.accentChoice === preset.id} />
- <span class="swatch-dot" aria-hidden="true" />
- <span class="swatch-label">{preset.label}</span>
- </label>
- ))}
-
- <label class={`swatch swatch-custom${values.accentChoice === "custom" ? " on" : ""}`} title="Custom colour">
- <input type="radio" name="accent_choice" value="custom" checked={values.accentChoice === "custom"} />
- <input
- type="color"
- name="accent_custom"
- value={values.accentCustom || "#9c1f34"}
- aria-label="Custom accent colour"
- />
- <span class="swatch-label">Custom</span>
- </label>
- </div>
- </fieldset>
-
- <div class="grid2">
- <label class="field">
- <span>Expires</span>
- <select name="expiry">
- {EXPIRY_OPTIONS.map((option) => (
- <option value={option.id} selected={option.id === values.expiry}>
- {option.label}
- </option>
- ))}
- </select>
- </label>
-
- <label class="check field-check">
- <input type="checkbox" name="unlisted" value="1" checked={values.unlisted} />
- <span>
- Unlisted
- <small class="muted"> — reachable by link, kept off the front page.</small>
- </span>
- </label>
- </div>
-
- <div class="buttons">
- <button type="submit" class="primary">
- {editing ? "Save changes" : "Publish paste"}
- </button>
- <a class="btn" href={editing ? `/${editing}` : "/"}>
- Cancel
- </a>
- </div>
- </form>
- );
-}
-
-export interface PasteViewProps {
- paste: PasteWithAuthor;
- html: string;
- lines: number;
- numbered: boolean;
- highlighted: boolean;
- /** The chosen theme is built for a light page, so the frame follows it. */
- light: boolean;
- jpml: JpmlCheck | null;
- isOwner: boolean;
- csrf: string;
- size: number;
- flash?: string | undefined;
-}
-
-export function PasteView(props: PasteViewProps) {
- const { paste } = props;
- const title = paste.title ?? paste.slug;
- const author = paste.author_name ?? paste.author_username;
-
- return (
- <article class="paste">
- <header class="paste-head">
- <div class="grow">
- <h1>{title}</h1>
- <p class="muted small paste-meta">
- <span>
- by <strong>{author}</strong>
- </span>
- <span aria-hidden="true">·</span>
- <span title={date(paste.created_at)}>{relative(paste.created_at)}</span>
- {paste.updated_at !== paste.created_at && (
- <>
- <span aria-hidden="true">·</span>
- <span title={date(paste.updated_at)}>edited {relative(paste.updated_at)}</span>
- </>
- )}
- <span aria-hidden="true">·</span>
- <span>{languageLabel(paste.language)}</span>
- <span aria-hidden="true">·</span>
- <span>
- {props.lines} {props.lines === 1 ? "line" : "lines"}, {bytes(props.size)}
- </span>
- {paste.unlisted === 1 && <span class="badge">unlisted</span>}
- {paste.expires_at !== null && (
- <span class="badge danger" title={date(paste.expires_at)}>
- expires {relative(paste.expires_at)}
- </span>
- )}
- </p>
- </div>
-
- <div class="buttons paste-actions">
- <button type="button" class="small" data-copy-body title="Copy the paste to the clipboard">
- Copy
- </button>
- <a class="btn small" href={`/raw/${paste.slug}`}>
- Raw
- </a>
- <a class="btn small" href={`/dl/${paste.slug}`}>
- Download
- </a>
- {props.isOwner && (
- <>
- <a class="btn small" href={`/${paste.slug}/edit`}>
- Edit
- </a>
- <form method="post" action={`/${paste.slug}/delete`} class="inline" data-confirm-delete>
- <Csrf token={props.csrf} />
- <button type="submit" class="small danger">
- Delete
- </button>
- </form>
- </>
- )}
- </div>
- </header>
-
- {props.jpml && !props.jpml.ok && (
- <p class="notice error jpml-note" role="status">
- <strong>JPML:</strong> {props.jpml.message}{" "}
- {props.jpml.line !== undefined && (
- <>
- at <a href={`#L${props.jpml.line}`}>line {props.jpml.line}</a>
- {props.jpml.col !== undefined && `, column ${props.jpml.col}`}
- </>
- )}
- </p>
- )}
- {props.jpml?.ok && (
- <p class="notice ok jpml-note" role="status">
- <strong>JPML:</strong> this document parses cleanly.
- </p>
- )}
-
- {!props.highlighted && paste.language !== "text" && (
- <p class="notice jpml-note">
- Too large to highlight — showing it as plain text.
- </p>
- )}
-
- <div
- class={`code${props.numbered ? " numbered" : ""}${props.light && props.highlighted ? " light" : ""}`}
- data-lines={String(props.lines)}
- >
- {raw(props.html)}
- </div>
- </article>
- );
-}
-
-export function PasteRows(props: { pastes: PasteWithAuthor[]; showAuthor?: boolean; empty: string }) {
- if (props.pastes.length === 0) return <p class="muted">{props.empty}</p>;
-
- return (
- <ul class="rows paste-rows">
- {props.pastes.map((paste) => (
- <li>
- <div class="grow">
- <a class="paste-link" href={`/${paste.slug}`}>
- {paste.title ?? paste.slug}
- </a>
- <p class="muted small paste-meta">
- <code>/{paste.slug}</code>
- <span aria-hidden="true">·</span>
- <span>{languageLabel(paste.language)}</span>
- {props.showAuthor !== false && (
- <>
- <span aria-hidden="true">·</span>
- <span>{paste.author_name ?? paste.author_username}</span>
- </>
- )}
- <span aria-hidden="true">·</span>
- <span title={date(paste.created_at)}>{relative(paste.created_at)}</span>
- {paste.unlisted === 1 && <span class="badge">unlisted</span>}
- {paste.expires_at !== null && <span class="badge danger">expiring</span>}
- </p>
- </div>
- </li>
- ))}
- </ul>
- );
-}
diff --git a/src/views/ui.tsx b/src/views/ui.tsx
deleted file mode 100644
index 42ee019..0000000
--- a/src/views/ui.tsx
+++ /dev/null
@@ -1,103 +0,0 @@
-/* src/views/ui.tsx
- * 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.
- */
-
-import type { Child } from "hono/jsx";
-
-// Flash messages travel as a fixed code in `?m=`, never as free text, so a
-// crafted link can't put words in this site's mouth.
-const MESSAGES: Record<string, string> = {
- "signed-in": "You're signed in.",
- "signed-out": "You're signed out.",
- "paste-created": "Paste published.",
- "paste-updated": "Paste updated.",
- "paste-deleted": "Paste deleted.",
- "sign-in-needed": "Sign in to publish a paste.",
-};
-
-export function Flash(props: { code?: string | undefined }) {
- const text = props.code ? MESSAGES[props.code] : undefined;
- return text ? <p class="notice ok">{text}</p> : null;
-}
-
-export function ErrorNote(props: { error?: string | null | undefined }) {
- return props.error ? (
- <p class="notice error" role="alert">
- {props.error}
- </p>
- ) : null;
-}
-
-export function Csrf(props: { token: string }) {
- return <input type="hidden" name="_csrf" value={props.token} />;
-}
-
-export function Section(props: { title: string; children?: Child; id?: string; description?: string }) {
- return (
- <section class="panel" id={props.id}>
- <h2>{props.title}</h2>
- {props.description && <p class="muted">{props.description}</p>}
- {props.children}
- </section>
- );
-}
-
-export function date(ts: number | null | undefined): string {
- if (!ts) return "never";
- return new Date(ts * 1000).toISOString().slice(0, 16).replace("T", " ") + " UTC";
-}
-
-export function relative(ts: number | null | undefined): string {
- if (!ts) return "never";
- const diff = Math.floor(Date.now() / 1000) - ts;
- const future = diff < 0;
- const abs = Math.abs(diff);
- const unit =
- abs < 60 ? [abs, "second"] :
- abs < 3600 ? [Math.floor(abs / 60), "minute"] :
- abs < 86400 ? [Math.floor(abs / 3600), "hour"] :
- [Math.floor(abs / 86400), "day"];
- const [n, word] = unit as [number, string];
- const text = `${n} ${word}${n === 1 ? "" : "s"}`;
- return future ? `in ${text}` : `${text} ago`;
-}
-
-export function bytes(count: number): string {
- if (count < 1024) return `${count} B`;
- if (count < 1024 * 1024) return `${(count / 1024).toFixed(count < 10240 ? 1 : 0)} KB`;
- return `${(count / (1024 * 1024)).toFixed(1)} MB`;
-}
-
-/** Links to the next and previous page of a listing, when there is one. */
-export function Pager(props: { path: string; page: number; total: number; perPage: number }) {
- const pages = Math.max(1, Math.ceil(props.total / props.perPage));
- if (pages <= 1) return null;
- const link = (page: number) => (page <= 1 ? props.path : `${props.path}?page=${page}`);
- return (
- <nav class="pager">
- {props.page > 1 ? (
- <a class="btn small" href={link(props.page - 1)}>
- Newer
- </a>
- ) : (
- <span class="btn small" aria-disabled="true">
- Newer
- </span>
- )}
- <span class="muted small">
- Page {props.page} of {pages}
- </span>
- {props.page < pages ? (
- <a class="btn small" href={link(props.page + 1)}>
- Older
- </a>
- ) : (
- <span class="btn small" aria-disabled="true">
- Older
- </span>
- )}
- </nav>
- );
-}
diff --git a/static/background.avif b/static/background.avif
new file mode 100644
index 0000000..b286ce8
Binary files /dev/null and b/static/background.avif differ
diff --git a/public/static/favicon.svg b/static/favicon.svg
similarity index 100%
rename from public/static/favicon.svg
rename to static/favicon.svg
diff --git a/tsconfig.json b/tsconfig.json
index dab5dd9..279eb35 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,34 +1,14 @@
{
+ "extends": "$app/tsconfig",
+ "include": ["src", "scripts", "*.ts"],
+ "exclude": ["build", "node_modules"],
"compilerOptions": {
- // Environment setup & latest features
- "lib": ["ESNext", "DOM"],
- "target": "ESNext",
- "module": "Preserve",
- "moduleDetection": "force",
- "jsx": "react-jsx",
- "jsxImportSource": "hono/jsx",
- "allowJs": true,
- "types": ["bun"],
- "resolveJsonModule": true,
-
- // Bundler mode
- "moduleResolution": "bundler",
"allowImportingTsExtensions": true,
- "verbatimModuleSyntax": true,
- "noEmit": true,
-
- // Best practices
+ "resolveJsonModule": true,
"strict": true,
"skipLibCheck": true,
- "noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
- "noImplicitOverride": true,
-
- // Some stricter flags (disabled by default)
- "noUnusedLocals": false,
- "noUnusedParameters": false,
- "noPropertyAccessFromIndexSignature": false
- },
- "include": ["src/**/*", "public/static/*.js"],
- "exclude": ["node_modules"]
+ "noFallthroughCasesInSwitch": true,
+ "types": ["$app/types", "bun"]
+ }
}
diff --git a/vite.config.ts b/vite.config.ts
new file mode 100644
index 0000000..ca54f2d
--- /dev/null
+++ b/vite.config.ts
@@ -0,0 +1,48 @@
+/* vite.config.ts
+ * 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.
+ */
+
+import adapter from "@sveltejs/adapter-node";
+import { sveltekit } from "@sveltejs/kit/vite";
+import { defineConfig } from "vite";
+
+export default defineConfig({
+ plugins: [
+ sveltekit({
+ compilerOptions: {
+ // Runes everywhere except libraries
+ runes: ({ filename }) => (filename.split(/[/\\]/).includes("node_modules") ? undefined : true),
+ },
+ adapter: adapter(),
+ // Pastes are other people's text, so nothing inline runs or styles without a nonce
+ csp: {
+ mode: "auto",
+ directives: {
+ "default-src": ["none"],
+ "script-src": ["self"],
+ "style-src": ["self"],
+ "img-src": ["self", "https:", "data:"],
+ "font-src": ["self", "https://raw.doughmination.gay"],
+ "connect-src": ["self"],
+ "form-action": ["self"],
+ "base-uri": ["none"],
+ "frame-ancestors": ["none"],
+ },
+ },
+ }),
+ ],
+ // iconsax fetches its icon data relative to its own file, which pre-bundling breaks
+ optimizeDeps: {
+ exclude: ["iconsax"],
+ },
+ ssr: {
+ external: ["bun:sqlite"],
+ },
+ build: {
+ rollupOptions: {
+ external: ["bun:sqlite"],
+ },
+ },
+});