Don't blow up when frontmatter YAML is invalid
This commit is contained in:
parent
5d89e15959
commit
56e5466b19
@ -81,6 +81,7 @@ export function extractMeta(
|
|||||||
// Find FrontMatter and parse it
|
// Find FrontMatter and parse it
|
||||||
if (t.type === "FrontMatter") {
|
if (t.type === "FrontMatter") {
|
||||||
const yamlText = renderToText(t.children![1].children![0]);
|
const yamlText = renderToText(t.children![1].children![0]);
|
||||||
|
try {
|
||||||
const parsedData: any = YAML.parse(yamlText);
|
const parsedData: any = YAML.parse(yamlText);
|
||||||
const newData = { ...parsedData };
|
const newData = { ...parsedData };
|
||||||
data = { ...data, ...parsedData };
|
data = { ...data, ...parsedData };
|
||||||
@ -101,6 +102,9 @@ export function extractMeta(
|
|||||||
if (Object.keys(newData).length === 0) {
|
if (Object.keys(newData).length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error("Could not parse frontmatter", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a fenced code block with `meta` as the language type
|
// Find a fenced code block with `meta` as the language type
|
||||||
|
Loading…
Reference in New Issue
Block a user