fixed md parsing for files without front matters
This commit is contained in:
parent
d899fbdee5
commit
bc7aad08fd
1 changed files with 8 additions and 4 deletions
|
@ -63,9 +63,9 @@ export default function parseMarkdown(
|
||||||
mode: ParseMode
|
mode: ParseMode
|
||||||
): MarkdownData {
|
): MarkdownData {
|
||||||
// todo: accurately calculate start and end of front matter
|
// todo: accurately calculate start and end of front matter
|
||||||
const frontMatter = matter(
|
const frontMatter = markdownRaw.startsWith("---")
|
||||||
markdownRaw.slice(0, nthIndex(markdownRaw, "---", 2) + 3)
|
? matter(markdownRaw.slice(0, nthIndex(markdownRaw, "---", 2) + 3)).data
|
||||||
).data
|
: {}
|
||||||
|
|
||||||
if (mode != ParseMode.PORTFOLIO) {
|
if (mode != ParseMode.PORTFOLIO) {
|
||||||
if (!frontMatter.title) throw Error(`Title is not defined in file: ${path}`)
|
if (!frontMatter.title) throw Error(`Title is not defined in file: ${path}`)
|
||||||
|
@ -85,7 +85,11 @@ export default function parseMarkdown(
|
||||||
//
|
//
|
||||||
|
|
||||||
const dom = new JSDOM(
|
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
|
// add .hljs class to all block codes
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue