Skip to content

Commit

Permalink
feat: create markdownToText.js to strip markdown string for metadata (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lumirlumir authored Sep 20, 2024
1 parent b0c8358 commit 4d88251
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/app/docs/[...categories]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join, sep } from 'path';

import { DOCS } from '@/constants/path';
import markdownToJsx, { readMarkdownWithFrontMatter } from '@/utils/markdownToJsx';
import markdownToText from '@/utils/markdownToText';

/* Custom Declaration */
function getFilePath(params) {
Expand Down Expand Up @@ -31,8 +32,8 @@ export async function generateMetadata({ params }) {
} = await readMarkdownWithFrontMatter(getFilePath(params));

return {
title,
description,
title: markdownToText(title),
description: markdownToText(description),
};
}

Expand Down
9 changes: 9 additions & 0 deletions src/utils/markdownToText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function markdownToText(markdown) {
return (
markdown
// Inline Code Block(`)
.replace(/`(.+?)`/g, '$1')
// Italic(*), Bold(**), Italic & Bold(***)
.replace(/(\*{1,3})(\S)(.*?\S)??\1/g, '$2$3')
);
}

0 comments on commit 4d88251

Please sign in to comment.