mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
Fix post toc id
update dependencies
This commit is contained in:
@ -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;
|
||||
|
@ -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",
|
||||
|
16
yarn.lock
16
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"
|
||||
|
Reference in New Issue
Block a user