Fixes #416: remove frontmatter when including or using a template
This commit is contained in:
parent
a5ae15e803
commit
260c91e4b1
@ -14,6 +14,7 @@ import {
|
|||||||
export async function extractFrontmatter(
|
export async function extractFrontmatter(
|
||||||
tree: ParseTree,
|
tree: ParseTree,
|
||||||
removeKeys: string[] = [],
|
removeKeys: string[] = [],
|
||||||
|
removeFrontmatterSection = false,
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
let data: any = {};
|
let data: any = {};
|
||||||
addParentPointers(tree);
|
addParentPointers(tree);
|
||||||
@ -55,7 +56,7 @@ export async function extractFrontmatter(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If nothing is left, let's just delete this whole block
|
// If nothing is left, let's just delete this whole block
|
||||||
if (Object.keys(newData).length === 0) {
|
if (Object.keys(newData).length === 0 || removeFrontmatterSection) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
@ -45,15 +45,15 @@ export async function templateDirectiveRenderer(
|
|||||||
} else {
|
} else {
|
||||||
templateText = await space.readPage(template);
|
templateText = await space.readPage(template);
|
||||||
}
|
}
|
||||||
let newBody = templateText;
|
const tree = await markdown.parseMarkdown(templateText);
|
||||||
|
await extractFrontmatter(tree, [], true); // Remove entire frontmatter section, if any
|
||||||
|
let newBody = renderToText(tree);
|
||||||
|
|
||||||
// if it's a template injection (not a literal "include")
|
// if it's a template injection (not a literal "include")
|
||||||
if (directive === "use") {
|
if (directive === "use") {
|
||||||
const tree = await markdown.parseMarkdown(templateText);
|
|
||||||
await extractFrontmatter(tree, ["$disableDirectives"]);
|
|
||||||
templateText = renderToText(tree);
|
|
||||||
registerHandlebarsHelpers();
|
registerHandlebarsHelpers();
|
||||||
const templateFn = Handlebars.compile(
|
const templateFn = Handlebars.compile(
|
||||||
replaceTemplateVars(templateText, pageName),
|
replaceTemplateVars(newBody, pageName),
|
||||||
{ noEscape: true },
|
{ noEscape: true },
|
||||||
);
|
);
|
||||||
if (typeof parsedArgs !== "string") {
|
if (typeof parsedArgs !== "string") {
|
||||||
|
Loading…
Reference in New Issue
Block a user