Skip to content

Commit

Permalink
feat: 기본 slug frontmatter 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkim0 committed Jan 7, 2024
1 parent adee35f commit 67dab32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@docusaurus/tsconfig",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"lib": ["ES2021.String"]
}
}

1 comment on commit 67dab32

@jmkim0
Copy link
Owner Author

@jmkim0 jmkim0 commented on 67dab32 Jan 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2

Please sign in to comment.