diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-08-28 21:33:44 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-08-28 21:33:44 -0500 |
commit | f0c03a9b8e15387c4defd0a0e3e0298324406fae (patch) | |
tree | 564011d0265666953b17258954ff68614ff6566a /utils | |
parent | 2f0439621cff059e414d67f6ce43a7a6c4de13bc (diff) | |
download | homepage-f0c03a9b8e15387c4defd0a0e3e0298324406fae.tar.xz homepage-f0c03a9b8e15387c4defd0a0e3e0298324406fae.zip |
Add wg2nd
Diffstat (limited to 'utils')
-rw-r--r-- | utils/Posts.tsx | 26 | ||||
-rw-r--r-- | utils/markedOptions.js | 2 |
2 files changed, 19 insertions, 9 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 +}; diff --git a/utils/markedOptions.js b/utils/markedOptions.js index ebc7a6f..26c208c 100644 --- a/utils/markedOptions.js +++ b/utils/markedOptions.js @@ -9,4 +9,4 @@ function highlight(code, lang) { module.exports = { highlight -};
\ No newline at end of file +}; |