From 5bcc2ecba8844953885c2ad76387a8ac7367e793 Mon Sep 17 00:00:00 2001 From: DefectingCat Date: Sun, 21 Aug 2022 21:54:59 +0800 Subject: [PATCH] Fix post toc id update dependencies --- lib/utils/index.ts | 14 ++++++++++++-- package.json | 4 ++-- yarn.lock | 16 ++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/utils/index.ts b/lib/utils/index.ts index 4439f23..572b70e 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -40,6 +40,11 @@ export type SingleToc = { link: string; children: SingleToc[]; }; +/** + * Generate post toc + * @param source + * @returns + */ export const generateToc = (source: string) => { const regex = /^#{2,3}(?!#)(.*)/gm; @@ -50,12 +55,17 @@ export const generateToc = (source: string) => { const heading = h.split(' '); const level = heading[0].length; const head = h.substring(level + 1); + const link = `#${head + .toLocaleLowerCase() + .replace(/ /g, '-') + .replace(/\./g, '')}`; + switch (level) { case 2: { lastH2 = { level, head, - link: `#${head.toLocaleLowerCase().replace(/ /g, '-')}`, + link, children: [], }; toc.push(lastH2); @@ -65,7 +75,7 @@ export const generateToc = (source: string) => { lastH2?.children.push({ level, head, - link: `#${head.toLocaleLowerCase().replace(/ /g, '-')}`, + link, children: [], }); break; diff --git a/package.json b/package.json index ef0e52e..6d1bba6 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "test-ci": "jest --ci --coverage" }, "dependencies": { - "@codesandbox/sandpack-react": "^1.5.0", + "@codesandbox/sandpack-react": "^1.5.1", "@docsearch/react": "3", "@giscus/react": "^2.2.0", "@mapbox/rehype-prism": "^0.8.0", @@ -37,7 +37,7 @@ "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.3.0", "@types/jest": "^28.1.7", - "@types/node": "18.7.6", + "@types/node": "18.7.8", "@types/react": "18.0.17", "autoprefixer": "^10.4.8", "dotenv": "^16.0.1", diff --git a/yarn.lock b/yarn.lock index 451fb69..eae4139 100644 --- a/yarn.lock +++ b/yarn.lock @@ -848,10 +848,10 @@ codesandbox-import-utils "^1.2.3" lodash.isequal "^4.5.0" -"@codesandbox/sandpack-react@^1.5.0": - version "1.5.0" - resolved "https://registry.npmmirror.com/@codesandbox/sandpack-react/-/sandpack-react-1.5.0.tgz#06314b688319edf97f8ca40f26be754ba41aeff0" - integrity sha512-Iz40LpIdCAHLsCfj2bNr917OqftpXVGKWpmvPFokqZ7j2/ax2Uf3KaIu/PNm9RYC/aKuNJ2O7fFZyCULNm/olw== +"@codesandbox/sandpack-react@^1.5.1": + version "1.5.1" + resolved "https://registry.npmmirror.com/@codesandbox/sandpack-react/-/sandpack-react-1.5.1.tgz#463231882aa618e5335eb971cd19bf7db0cfca35" + integrity sha512-WuNPgRiR1fdaPkrVs+n/Kqx5bOqI5C4MS3XsQaRXng/Cph0TBdoKxGFVs+9/sZpgid5g16A6O3EZVREQE6Sc3g== dependencies: "@code-hike/classer" "^0.0.0-aa6efee" "@codemirror/closebrackets" "^0.19.0" @@ -1967,10 +1967,10 @@ resolved "https://registry.npmmirror.com/@types/node/-/node-17.0.22.tgz#38b6c4b9b2f3ed9f2e376cce42a298fb2375251e" integrity sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw== -"@types/node@18.7.6": - version "18.7.6" - resolved "https://registry.npmmirror.com/@types/node/-/node-18.7.6.tgz#31743bc5772b6ac223845e18c3fc26f042713c83" - integrity sha512-EdxgKRXgYsNITy5mjjXjVE/CS8YENSdhiagGrLqjG0pvA2owgJ6i4l7wy/PFZGC0B1/H20lWKN7ONVDNYDZm7A== +"@types/node@18.7.8": + version "18.7.8" + resolved "https://registry.npmmirror.com/@types/node/-/node-18.7.8.tgz#6bbf2be6fbf9c187a5040d4277d24a06a18957a1" + integrity sha512-/YP55EMK2341JkODUb8DM9O0x1SIz2aBvyF33Uf1c76St3VpsMXEIW0nxuKkq/5cxnbz0RD9cfwNZHEAZQD3ag== "@types/parse5@*": version "6.0.3"