feat: add rehype-slug & @stefanprobst/rehype-extract-toc to provide toc

This commit is contained in:
p-sw 2024-06-02 06:56:59 +09:00
parent 8b53e0a0e4
commit a042157626
3 changed files with 140 additions and 2 deletions

View File

@ -11,11 +11,13 @@
},
"dependencies": {
"@mdx-js/react": "^3.0.1",
"@stefanprobst/rehype-extract-toc": "^2.2.0",
"highlight.js": "^11.9.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.23.1",
"rehype-highlight": "^7.0.0",
"rehype-slug": "^6.0.0",
"remark-gfm": "^4.0.0",
"tailwind-merge": "^2.3.0"
},

View File

@ -5,10 +5,13 @@ import mdx from '@mdx-js/rollup';
import { resolve } from 'node:path';
import rehypeHighlight from "rehype-highlight";
import remarkGfm from "remark-gfm";
import withSlug from "rehype-slug"
import withToc from "@stefanprobst/rehype-extract-toc";
import withTocExport from "@stefanprobst/rehype-extract-toc/mdx";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), mdx({ rehypePlugins: [rehypeHighlight], remarkPlugins: [remarkGfm] })],
plugins: [react(), mdx({ rehypePlugins: [rehypeHighlight, withSlug, withToc, withTocExport], remarkPlugins: [remarkGfm] })],
css: {
postcss: {
plugins: [tailwindcss()],

135
yarn.lock
View File

@ -818,6 +818,19 @@ __metadata:
languageName: node
linkType: hard
"@stefanprobst/rehype-extract-toc@npm:^2.2.0":
version: 2.2.0
resolution: "@stefanprobst/rehype-extract-toc@npm:2.2.0"
dependencies:
estree-util-is-identifier-name: "npm:^2.0.1"
estree-util-value-to-estree: "npm:^1.3.0"
hast-util-heading-rank: "npm:^2.1.0"
hast-util-to-string: "npm:^2.0.0"
unist-util-visit: "npm:^4.1.0"
checksum: 10c0/eb7ab3e39c6f6f4ba6d10642ebe533fe23ad7348195eaf77490ba6e0e0c9dfd27231e64b402ea3f98c6e583a933ddcd5b27ab64eb07b36aab27c31ddf77116d8
languageName: node
linkType: hard
"@storybook/csf@npm:^0.0.1":
version: 0.0.1
resolution: "@storybook/csf@npm:0.0.1"
@ -916,6 +929,15 @@ __metadata:
languageName: node
linkType: hard
"@types/hast@npm:^2.0.0":
version: 2.3.10
resolution: "@types/hast@npm:2.3.10"
dependencies:
"@types/unist": "npm:^2"
checksum: 10c0/16daac35d032e656defe1f103f9c09c341a6dc553c7ec17b388274076fa26e904a71ea5ea41fd368a6d5f1e9e53be275c80af7942b9c466d8511d261c9529c7e
languageName: node
linkType: hard
"@types/hast@npm:^3.0.0":
version: 3.0.4
resolution: "@types/hast@npm:3.0.4"
@ -1032,7 +1054,7 @@ __metadata:
languageName: node
linkType: hard
"@types/unist@npm:^2.0.0":
"@types/unist@npm:^2, @types/unist@npm:^2.0.0":
version: 2.0.10
resolution: "@types/unist@npm:2.0.10"
checksum: 10c0/5f247dc2229944355209ad5c8e83cfe29419fa7f0a6d557421b1985a1500444719cc9efcc42c652b55aab63c931813c88033e0202c1ac684bcd4829d66e44731
@ -2095,6 +2117,13 @@ __metadata:
languageName: node
linkType: hard
"estree-util-is-identifier-name@npm:^2.0.1":
version: 2.1.0
resolution: "estree-util-is-identifier-name@npm:2.1.0"
checksum: 10c0/cc241a6998d30f4e8775ec34b042ef93e0085cd1bdf692a01f22e9b748f0866c76679475ff87935be1d8d5b1a7648be8cba366dc60866b372269f35feec756fe
languageName: node
linkType: hard
"estree-util-is-identifier-name@npm:^3.0.0":
version: 3.0.0
resolution: "estree-util-is-identifier-name@npm:3.0.0"
@ -2113,6 +2142,15 @@ __metadata:
languageName: node
linkType: hard
"estree-util-value-to-estree@npm:^1.3.0":
version: 1.3.0
resolution: "estree-util-value-to-estree@npm:1.3.0"
dependencies:
is-plain-obj: "npm:^3.0.0"
checksum: 10c0/8bf46c4629f55a6ad3a6c523277cd34591cf57dfcab01cf4f218a8780cd23d21901c393693484c449a46bad7b9cb6fbf24c3dd1c1b057e10fd6a076f24fd5f3f
languageName: node
linkType: hard
"estree-util-visit@npm:^2.0.0":
version: 2.0.0
resolution: "estree-util-visit@npm:2.0.0"
@ -2324,6 +2362,13 @@ __metadata:
languageName: node
linkType: hard
"github-slugger@npm:^2.0.0":
version: 2.0.0
resolution: "github-slugger@npm:2.0.0"
checksum: 10c0/21b912b6b1e48f1e5a50b2292b48df0ff6abeeb0691b161b3d93d84f4ae6b1acd6ae23702e914af7ea5d441c096453cf0f621b72d57893946618d21dd1a1c486
languageName: node
linkType: hard
"glob-parent@npm:^5.1.2, glob-parent@npm:~5.1.2":
version: 5.1.2
resolution: "glob-parent@npm:5.1.2"
@ -2438,6 +2483,24 @@ __metadata:
languageName: node
linkType: hard
"hast-util-heading-rank@npm:^2.1.0":
version: 2.1.1
resolution: "hast-util-heading-rank@npm:2.1.1"
dependencies:
"@types/hast": "npm:^2.0.0"
checksum: 10c0/e1451ae71ea4b524aae1e772063dabb44c13d812de198d6a2841d5d5425c64414d0a81df745bde00f1393b4cbc6990b91b5614f4f895183120ee418fa50ed2c7
languageName: node
linkType: hard
"hast-util-heading-rank@npm:^3.0.0":
version: 3.0.0
resolution: "hast-util-heading-rank@npm:3.0.0"
dependencies:
"@types/hast": "npm:^3.0.0"
checksum: 10c0/1879c84f629e73f1f13247ab349324355cd801363b44e3d46f763aa5c0ea3b42dcd47b46e5643a0502cf01a6b1fdb9208fd12852e44ca6c671b3e4bccf9369a1
languageName: node
linkType: hard
"hast-util-is-element@npm:^3.0.0":
version: 3.0.0
resolution: "hast-util-is-element@npm:3.0.0"
@ -2494,6 +2557,24 @@ __metadata:
languageName: node
linkType: hard
"hast-util-to-string@npm:^2.0.0":
version: 2.0.0
resolution: "hast-util-to-string@npm:2.0.0"
dependencies:
"@types/hast": "npm:^2.0.0"
checksum: 10c0/9cf78d0de776e379476408d8363eeb690421e1b042919cfd97651eb968dbfe4ca9f5e4e23478a8d2c0d84a5432478d02d4c8ceef294b903becc5e8b71fa12849
languageName: node
linkType: hard
"hast-util-to-string@npm:^3.0.0":
version: 3.0.0
resolution: "hast-util-to-string@npm:3.0.0"
dependencies:
"@types/hast": "npm:^3.0.0"
checksum: 10c0/649edd993cf244563ad86d861aa0863759a4fbec49c43b3d92240e42aa4b69f0c3332ddff9e80954bbd8756c86b0fddc20e97d281c6da59d00427f45da8dab68
languageName: node
linkType: hard
"hast-util-to-text@npm:^4.0.0":
version: 4.0.2
resolution: "hast-util-to-text@npm:4.0.2"
@ -2723,6 +2804,13 @@ __metadata:
languageName: node
linkType: hard
"is-plain-obj@npm:^3.0.0":
version: 3.0.0
resolution: "is-plain-obj@npm:3.0.0"
checksum: 10c0/8e6483bfb051d42ec9c704c0ede051a821c6b6f9a6c7a3e3b55aa855e00981b0580c8f3b1f5e2e62649b39179b1abfee35d6f8086d999bfaa32c1908d29b07bc
languageName: node
linkType: hard
"is-plain-obj@npm:^4.0.0":
version: 4.1.0
resolution: "is-plain-obj@npm:4.1.0"
@ -4250,6 +4338,7 @@ __metadata:
dependencies:
"@mdx-js/react": "npm:^3.0.1"
"@mdx-js/rollup": "npm:^3.0.1"
"@stefanprobst/rehype-extract-toc": "npm:^2.2.0"
"@tailwindcss/typography": "npm:^0.5.13"
"@types/mdx": "npm:^2.0.13"
"@types/node": "npm:^20.12.13"
@ -4270,6 +4359,7 @@ __metadata:
react-dom: "npm:^18.2.0"
react-router-dom: "npm:^6.23.1"
rehype-highlight: "npm:^7.0.0"
rehype-slug: "npm:^6.0.0"
remark-gfm: "npm:^4.0.0"
tailwind-merge: "npm:^2.3.0"
tailwindcss: "npm:^3.4.3"
@ -4316,6 +4406,19 @@ __metadata:
languageName: node
linkType: hard
"rehype-slug@npm:^6.0.0":
version: 6.0.0
resolution: "rehype-slug@npm:6.0.0"
dependencies:
"@types/hast": "npm:^3.0.0"
github-slugger: "npm:^2.0.0"
hast-util-heading-rank: "npm:^3.0.0"
hast-util-to-string: "npm:^3.0.0"
unist-util-visit: "npm:^5.0.0"
checksum: 10c0/51303c33d039c271cabe62161b49fa737be488f70ced62f00c165e47a089a99de2060050385e5c00d0df83ed30c7fa1c79a51b78508702836aefa51f7e7a6760
languageName: node
linkType: hard
"remark-gfm@npm:^4.0.0":
version: 4.0.0
resolution: "remark-gfm@npm:4.0.0"
@ -5004,6 +5107,15 @@ __metadata:
languageName: node
linkType: hard
"unist-util-is@npm:^5.0.0":
version: 5.2.1
resolution: "unist-util-is@npm:5.2.1"
dependencies:
"@types/unist": "npm:^2.0.0"
checksum: 10c0/a2376910b832bb10653d2167c3cd85b3610a5fd53f5169834c08b3c3a720fae9043d75ad32d727eedfc611491966c26a9501d428ec62467edc17f270feb5410b
languageName: node
linkType: hard
"unist-util-is@npm:^6.0.0":
version: 6.0.0
resolution: "unist-util-is@npm:6.0.0"
@ -5050,6 +5162,16 @@ __metadata:
languageName: node
linkType: hard
"unist-util-visit-parents@npm:^5.1.1":
version: 5.1.3
resolution: "unist-util-visit-parents@npm:5.1.3"
dependencies:
"@types/unist": "npm:^2.0.0"
unist-util-is: "npm:^5.0.0"
checksum: 10c0/f6829bfd8f2eddf63a32e2c302cd50978ef0c194b792c6fe60c2b71dfd7232415a3c5941903972543e9d34e6a8ea69dee9ccd95811f4a795495ed2ae855d28d0
languageName: node
linkType: hard
"unist-util-visit-parents@npm:^6.0.0":
version: 6.0.1
resolution: "unist-util-visit-parents@npm:6.0.1"
@ -5060,6 +5182,17 @@ __metadata:
languageName: node
linkType: hard
"unist-util-visit@npm:^4.1.0":
version: 4.1.2
resolution: "unist-util-visit@npm:4.1.2"
dependencies:
"@types/unist": "npm:^2.0.0"
unist-util-is: "npm:^5.0.0"
unist-util-visit-parents: "npm:^5.1.1"
checksum: 10c0/56a1f49a4d8e321e75b3c7821d540a45165a031dd06324bb0e8c75e7737bc8d73bdddbf0b0ca82000f9708a4c36861c6ebe88d01f7cf00e925f5d75f13a3a017
languageName: node
linkType: hard
"unist-util-visit@npm:^5.0.0":
version: 5.0.0
resolution: "unist-util-visit@npm:5.0.0"