From 2c5771d43959a8a644a8ad64e2f1ac9394756e33 Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:35:24 -0800 Subject: [PATCH 1/2] implement markdown-it-toc-done-right --- components/blog_page/markdown.ts | 3 +++ components/blog_page/posts.ts | 9 +++++++-- deno.json | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/blog_page/markdown.ts b/components/blog_page/markdown.ts index c87714f..fa33375 100644 --- a/components/blog_page/markdown.ts +++ b/components/blog_page/markdown.ts @@ -1,5 +1,6 @@ import MarkdownIt from "markdown-it"; import anchorPlugin from "markdown-it-anchor"; +import tocDoneRightPlugin from "markdown-it-toc-done-right"; import hljs from "highlight.js"; /** @@ -35,3 +36,5 @@ renderer.use(anchorPlugin, { class: "fart-link-visible-on-hover", }), }); + +renderer.use(tocDoneRightPlugin); diff --git a/components/blog_page/posts.ts b/components/blog_page/posts.ts index e970cfa..073de85 100644 --- a/components/blog_page/posts.ts +++ b/components/blog_page/posts.ts @@ -66,12 +66,16 @@ export function readPostSync(entry: WalkEntry): Post { return { id, attrs: extracted.attrs, - html: renderHTML(extracted.body), + html: renderHTML( + `${(extracted.attrs.toc ?? true) ? tocPrefix : ""}${extracted.body}`, + ), }; } +const tocPrefix = "## On this page\n\n[[toc]]\n"; + /** - * constTopics counts the topics. + * countTopics counts the topics. */ export function countTopics(posts: Post[]): Map { const topics = new Map(); @@ -115,6 +119,7 @@ export interface PostAttrs { topics: string[]; date: Date; aliases?: string[]; + toc?: boolean; } /** diff --git a/deno.json b/deno.json index 478f673..b04a027 100644 --- a/deno.json +++ b/deno.json @@ -16,6 +16,7 @@ "highlight.js": "npm:highlight.js@^11.9.0", "markdown-it": "npm:markdown-it@^14.1.0", "markdown-it-anchor": "npm:markdown-it-anchor@^9.0.0", + "markdown-it-toc-done-right": "npm:markdown-it-toc-done-right@^4.2.0", "simplex-noise": "npm:simplex-noise@^4.0.1" }, "tasks": { From 6d26c16348dcb6c2b6b0ff8db8fc2ecc7aa3b4ff Mon Sep 17 00:00:00 2001 From: Ethan Davidson <31261035+EthanThatOneKid@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:42:50 -0800 Subject: [PATCH 2/2] blog: games post skips toc --- blog/games.md | 1 + 1 file changed, 1 insertion(+) diff --git a/blog/games.md b/blog/games.md index 9b0d83e..0289149 100644 --- a/blog/games.md +++ b/blog/games.md @@ -6,6 +6,7 @@ authors: username: "EthanThatOneKid" topics: ["Games"] date: 2024-06-05 +toc: false --- At FartLabs, we're passionate about developer tools, but we also love creating