aboutsummaryrefslogtreecommitdiff
path: root/utils/Posts.tsx
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2023-08-28 21:33:44 -0500
committerFurkan Sahin <furkan-dev@proton.me>2023-08-28 21:33:44 -0500
commit2a308fb5bec47aac0f59e074d793cec6e95db1c3 (patch)
treee8d8026ab7074ae1c273c819e049eb211309e04f /utils/Posts.tsx
parenta0e64e73ef07c1cc3623d2712c483bf45884d350 (diff)
Add wg2nd
Diffstat (limited to 'utils/Posts.tsx')
-rw-r--r--utils/Posts.tsx26
1 files changed, 18 insertions, 8 deletions
diff --git a/utils/Posts.tsx b/utils/Posts.tsx
index fed1d31..4b252da 100644
--- a/utils/Posts.tsx
+++ b/utils/Posts.tsx
@@ -1,16 +1,21 @@
import { promises as fs } from 'fs';
import path from 'path';
// @ts-ignore
-import { marked } from 'marked';
+import { Marked } from 'marked';
+import { markedHighlight } from 'marked-highlight';
import markedOptions from './markedOptions';
-marked.setOptions(markedOptions);
+const hljs = require('highlight.js');
+
+const marker = new Marked(
+ markedHighlight(markedOptions)
+);
interface PostMetadata {
name: string;
lastUpdated: string;
}
-
+
interface Post {
directory: string;
path: string;
@@ -55,10 +60,10 @@ async function getPosts() : Promise<Post[]> {
if(a === b)
return 0;
-
+
if(a > b)
return -1;
-
+
return 1;
});
}
@@ -68,13 +73,18 @@ async function getMarkdown(post : Post) : Promise<string> {
const markdown = await fs.readFile(markdownPath, 'utf8');
- const html = marked(markdown);
+ const html = marker.parse(markdown);
+
+ if(html === undefined) {
+ return '';
+ } else {
+ return html as string;
+ }
- return html;
}
export {
getPosts,
getMarkdown,
getPostFromDirectory
-}; \ No newline at end of file
+};