From f0c03a9b8e15387c4defd0a0e3e0298324406fae Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Mon, 28 Aug 2023 21:33:44 -0500 Subject: Add wg2nd --- utils/Posts.tsx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'utils/Posts.tsx') 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 { if(a === b) return 0; - + if(a > b) return -1; - + return 1; }); } @@ -68,13 +73,18 @@ async function getMarkdown(post : Post) : Promise { 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