From 67dab32b8472eddb8e6d3926cf2ab11789eb2830 Mon Sep 17 00:00:00 2001 From: Jimin Kim Date: Mon, 8 Jan 2024 03:01:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B8=B0=EB=B3=B8=20slug=20frontmatter?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docusaurus.config.ts | 16 +++++++++++++--- tsconfig.json | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docusaurus.config.ts b/docusaurus.config.ts index 85d66f2..aa3442d 100644 --- a/docusaurus.config.ts +++ b/docusaurus.config.ts @@ -33,15 +33,15 @@ const config: Config = { const items = await defaultSidebarItemsGenerator(args); function stripNumberPrefix(item) { - const regex = /^(\d{2}|\d{2}\.\d{2,3}) (.+)/; + const regex = /^(?:\d{2}|\d{2}\.\d{2,3}) (.+)/; if (item.type === 'doc') { const match = regex.exec(item.label); - return {...item, label: match ? match[2] : item.label}; + return {...item, label: match ? match[1] : item.label}; } else if (item.type === 'category') { const match = regex.exec(item.label); return { ...item, - label: match ? match[2] : item.label, + label: match ? match[1] : item.label, items: item.items.map(stripNumberPrefix), }; } @@ -145,6 +145,16 @@ const config: Config = { markdown: { format: 'detect', mermaid: true, + parseFrontMatter: async params => { + const result = await params.defaultParseFrontMatter(params); + const path = /(?:10 Wiki|20 Posts\/2\d)(.*)/.exec(params.filePath)[1]; + + result.frontMatter.slug = path + .replaceAll(/(?:\d{2}|\d{2}\.\d{2,3}) /g, '') + .replaceAll(' ', '+'); + + return result; + }, mdx1Compat: { comments: false, admonitions: false, diff --git a/tsconfig.json b/tsconfig.json index d250afa..e333dcd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "@docusaurus/tsconfig", "compilerOptions": { - "baseUrl": "." + "baseUrl": ".", + "lib": ["ES2021.String"] } }