aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/Posts.tsx26
-rw-r--r--utils/markedOptions.js2
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
+};