From bc7aad08fdc11dbbd76f1f7d15e2016c9e058514 Mon Sep 17 00:00:00 2001 From: developomp Date: Sat, 26 Mar 2022 21:01:59 +0900 Subject: [PATCH] fixed md parsing for files without front matters --- generate/parseMarkdown.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/generate/parseMarkdown.ts b/generate/parseMarkdown.ts index bfdaed6..4e94851 100644 --- a/generate/parseMarkdown.ts +++ b/generate/parseMarkdown.ts @@ -63,9 +63,9 @@ export default function parseMarkdown( mode: ParseMode ): MarkdownData { // todo: accurately calculate start and end of front matter - const frontMatter = matter( - markdownRaw.slice(0, nthIndex(markdownRaw, "---", 2) + 3) - ).data + const frontMatter = markdownRaw.startsWith("---") + ? matter(markdownRaw.slice(0, nthIndex(markdownRaw, "---", 2) + 3)).data + : {} if (mode != ParseMode.PORTFOLIO) { if (!frontMatter.title) throw Error(`Title is not defined in file: ${path}`) @@ -85,7 +85,11 @@ export default function parseMarkdown( // const dom = new JSDOM( - md.render(markdownRaw.slice(nthIndex(markdownRaw, "---", 2) + 3)) || "" + md.render( + markdownRaw.startsWith("---") + ? markdownRaw.slice(nthIndex(markdownRaw, "---", 2) + 3) + : markdownRaw + ) || "" ) // add .hljs class to all block codes