From 16baa822cc897fa8764c14861f7869f46ca50e30 Mon Sep 17 00:00:00 2001
From: Furkan Sahin <furkan-dev@proton.me>
Date: Mon, 30 May 2022 21:11:40 -0500
Subject: Compress results gif

---
 utils/Posts.tsx | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

(limited to 'utils/Posts.tsx')

diff --git a/utils/Posts.tsx b/utils/Posts.tsx
index fed1d31..291ea41 100644
--- a/utils/Posts.tsx
+++ b/utils/Posts.tsx
@@ -1,16 +1,24 @@
 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);
+import { renderer, hooks } from '../loaders/marked-renderer.js';
+
+const hljs = require('highlight.js');
+
+const marker = new Marked(
+  markedHighlight(markedOptions),
+  { renderer, hooks }
+);
 
 interface PostMetadata {
   name: string;
   lastUpdated: string;
 }
-  
+
 interface Post {
   directory: string;
   path: string;
@@ -55,10 +63,10 @@ async function getPosts() : Promise<Post[]> {
 
     if(a === b)
       return 0;
-    
+
     if(a > b)
       return -1;
-    
+
     return 1;
   });
 }
@@ -68,13 +76,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
+};
-- 
cgit v1.2.3

