From 5dfaf6a7c403ac3a5f298e5f05df35c4cbc2df83 Mon Sep 17 00:00:00 2001 From: Timothy Lin Date: Sat, 2 Nov 2024 11:52:29 +0800 Subject: [PATCH] fix: toc slug initialisation --- .changeset/heavy-dolls-search.md | 5 +++++ packages/pliny/src/mdx-plugins/remark-toc-headings.ts | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 .changeset/heavy-dolls-search.md diff --git a/.changeset/heavy-dolls-search.md b/.changeset/heavy-dolls-search.md new file mode 100644 index 0000000..c751ab3 --- /dev/null +++ b/.changeset/heavy-dolls-search.md @@ -0,0 +1,5 @@ +--- +'pliny': patch +--- + +fix toc slugs are tracked across documents diff --git a/packages/pliny/src/mdx-plugins/remark-toc-headings.ts b/packages/pliny/src/mdx-plugins/remark-toc-headings.ts index 7076e47..543cb2c 100644 --- a/packages/pliny/src/mdx-plugins/remark-toc-headings.ts +++ b/packages/pliny/src/mdx-plugins/remark-toc-headings.ts @@ -6,8 +6,6 @@ import GithubSlugger from 'github-slugger' import { toString } from 'mdast-util-to-string' import { remark } from 'remark' -const slugger = new GithubSlugger() - export type TocItem = { value: string url: string @@ -20,6 +18,7 @@ export type Toc = TocItem[] * Extracts TOC headings from markdown file and adds it to the file's data object. */ export function remarkTocHeadings() { + const slugger = new GithubSlugger() return (tree: Parent, file: VFile) => { const toc: Toc = [] visit(tree, 'heading', (node: Heading) => {