No longer index templates tagged as #template

This commit is contained in:
Zef Hemel
2023-11-09 09:26:44 +01:00
parent 366b2ed395
commit d58db6aa1a
19 changed files with 307 additions and 64 deletions
+6 -2
View File
@@ -28,7 +28,9 @@ export async function updateDirectivesOnPageCommand() {
}
const text = await editor.getText();
const tree = await markdown.parseMarkdown(text);
const metaData = await extractFrontmatter(tree, ["$disableDirectives"]);
const metaData = await extractFrontmatter(tree, {
removeKeys: ["$disableDirectives"],
});
if (isFederationPath(currentPage)) {
console.info("Current page is a federation page, not updating directives.");
@@ -173,7 +175,9 @@ async function updateDirectivesForPage(
const pageMeta = await space.getPageMeta(pageName);
const currentText = await space.readPage(pageName);
const tree = await markdown.parseMarkdown(currentText);
const metaData = await extractFrontmatter(tree, ["$disableDirectives"]);
const metaData = await extractFrontmatter(tree, {
removeKeys: ["$disableDirectives"],
});
if (isFederationPath(pageName)) {
console.info("Current page is a federation page, not updating directives.");
+2 -2
View File
@@ -1,7 +1,7 @@
import { events } from "$sb/syscalls.ts";
import { replaceTemplateVars } from "../template/template.ts";
import { renderTemplate } from "./util.ts";
import { renderQueryTemplate } from "./util.ts";
import { jsonToMDTable } from "./util.ts";
import { ParseTree, parseTreeToAST } from "$sb/lib/tree.ts";
import { astToKvQuery } from "$sb/lib/parse-query.ts";
@@ -38,7 +38,7 @@ export async function queryDirectiveRenderer(
// console.log("Parsed query", parsedQuery);
const allResults = results.flat();
if (parsedQuery.render) {
const rendered = await renderTemplate(
const rendered = await renderQueryTemplate(
pageMeta,
parsedQuery.render,
allResults,
+3 -4
View File
@@ -8,6 +8,7 @@ import { directiveRegex } from "./directives.ts";
import { updateDirectives } from "./command.ts";
import { resolvePath, rewritePageRefs } from "$sb/lib/resolve.ts";
import { PageMeta } from "$sb/types.ts";
import { renderTemplate } from "../template/plug_api.ts";
const templateRegex = /\[\[([^\]]+)\]\]\s*(.*)\s*/;
@@ -52,7 +53,7 @@ export async function templateDirectiveRenderer(
templateText = await space.readPage(templatePath);
}
const tree = await markdown.parseMarkdown(templateText);
await extractFrontmatter(tree, [], true); // Remove entire frontmatter section, if any
await extractFrontmatter(tree, { removeFrontmatterSection: true }); // Remove entire frontmatter section, if any
// Resolve paths in the template
rewritePageRefs(tree, templatePath);
@@ -63,9 +64,7 @@ export async function templateDirectiveRenderer(
// if it's a template injection (not a literal "include")
if (directive === "use") {
newBody = await handlebars.renderTemplate(newBody, parsedArgs, {
page: pageMeta,
});
newBody = await renderTemplate(newBody, pageMeta, parsedArgs);
// Recursively render directives
const tree = await markdown.parseMarkdown(newBody);
+5 -3
View File
@@ -1,6 +1,7 @@
import { handlebars, space } from "$sb/syscalls.ts";
import { handlebarHelpers } from "../../common/syscalls/handlebar_helpers.ts";
import { PageMeta } from "$sb/types.ts";
import { cleanTemplate, renderTemplate } from "../template/plug_api.ts";
export function defaultJsonTransformer(_k: string, v: any) {
if (v === undefined) {
@@ -53,13 +54,14 @@ export function jsonToMDTable(
return lines.join("\n");
}
export async function renderTemplate(
export async function renderQueryTemplate(
pageMeta: PageMeta,
renderTemplate: string,
templatePage: string,
data: any[],
renderAll: boolean,
): Promise<string> {
let templateText = await space.readPage(renderTemplate);
let templateText = await space.readPage(templatePage);
templateText = await cleanTemplate(templateText);
if (!renderAll) {
templateText = `{{#each .}}\n${templateText}\n{{/each}}`;
}