From 55d8b17aeccb48194cbaea9831286b4b73ac7059 Mon Sep 17 00:00:00 2001 From: "netop://ウィビ" Date: Wed, 22 Jul 2026 10:55:23 -0700 Subject: fixes canonical links --- main.ts | 10 ++++++---- src/helper/create-layout.ts | 8 +++++--- version.txt | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/main.ts b/main.ts index c3dbcc9..805d070 100644 --- a/main.ts +++ b/main.ts @@ -156,7 +156,8 @@ const server = Deno.serve({ } if (/^\/(WM-\d*)$/.test(pathname)) { - const slug = pathname.slice(1) + ".txt"; + const rawSlug = pathname.slice(1); + const slug = rawSlug + ".txt"; const posts = await getDocuments(memoDirectory); if (posts && posts.indexOf(slug) < 0) { @@ -172,7 +173,7 @@ const server = Deno.serve({ const listings = await getDirectoryContents(memoDirectory); return new Response( - createLayout("memo", await populateDocument({ filename: slug }), populateRecents(listings, slug)), { + createLayout("memo", await populateDocument({ filename: slug }), populateRecents(listings, slug), rawSlug), { headers: { "content-type": "text/html; charset=utf-8" } @@ -206,7 +207,8 @@ const server = Deno.serve({ } if (/^\/remarks\/(WR-\d*)$/.test(pathname)) { - const slug = pathname.split("/").pop() + ".txt"; + const rawSlug = pathname.split("/").pop(); + const slug = rawSlug + ".txt"; const posts = await getDocuments(remarkDirectory); if (posts && posts.indexOf(slug) < 0) { @@ -222,7 +224,7 @@ const server = Deno.serve({ const listings = await getDirectoryContents(remarkDirectory); return new Response( - createLayout("remark", await populateDocument({ filename: slug }), populateRecents(listings, slug)), { + createLayout("remark", await populateDocument({ filename: slug }), populateRecents(listings, slug), rawSlug), { headers: { "content-type": "text/html; charset=utf-8" } diff --git a/src/helper/create-layout.ts b/src/helper/create-layout.ts index f624c5f..93c71b5 100644 --- a/src/helper/create-layout.ts +++ b/src/helper/create-layout.ts @@ -14,8 +14,10 @@ import headerParser from "src/helper/parse-header.ts"; /*** EXPORT ------------------------------------------- ***/ -export default (type: "memo" | "remark", memo: string, recents: string) => { +export default (type: "memo" | "remark", memo: string, recents: string, slug?: string) => { const { abstract, /*category,*/ document, title: documentTitle } = headerParser(memo); + // https://news.ycombinator.com/item?id=48986710 + const canonicalUrl = slug ? `${url}/${slug}` : url; return ` @@ -37,7 +39,7 @@ export default (type: "memo" | "remark", memo: string, recents: string) => { - + @@ -51,7 +53,7 @@ export default (type: "memo" | "remark", memo: string, recents: string) => { - + diff --git a/version.txt b/version.txt index 6b75ba8..920a0e5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2026.07.20 \ No newline at end of file +2026.07.22 \ No newline at end of file -- cgit v1.2.3