Robustness and federation sync

This commit is contained in:
Zef Hemel
2023-07-30 11:30:01 +02:00
parent afa160d2c2
commit b584e2ef7e
11 changed files with 264 additions and 110 deletions
+1
View File
@@ -19,6 +19,7 @@ export async function updateDirectivesOnPageCommand() {
if (isFederationPath(currentPage)) {
console.info("Current page is a federation page, not updating directives.");
return;
}
if (metaData.$disableDirectives) {
+1 -35
View File
@@ -14,7 +14,7 @@ import { directiveRegex } from "./directives.ts";
import { updateDirectives } from "./command.ts";
import { buildHandebarOptions } from "./util.ts";
import { PageMeta } from "../../web/types.ts";
import { resolvePath } from "$sb/lib/resolve.ts";
import { resolvePath, rewritePageRefs } from "$sb/lib/resolve.ts";
const templateRegex = /\[\[([^\]]+)\]\]\s*(.*)\s*/;
@@ -82,40 +82,6 @@ export async function templateDirectiveRenderer(
return newBody.trim();
}
function rewritePageRefs(tree: ParseTree, templatePath: string) {
traverseTree(tree, (n): boolean => {
if (n.type === "DirectiveStart") {
const pageRef = findNodeOfType(n, "PageRef")!;
if (pageRef) {
const pageRefName = pageRef.children![0].text!.slice(2, -2);
pageRef.children![0].text = `[[${
resolvePath(templatePath, pageRefName)
}]]`;
}
const directiveText = n.children![0].text;
// #use or #import
if (directiveText) {
const match = /\[\[(.+)\]\]/.exec(directiveText);
if (match) {
const pageRefName = match[1];
n.children![0].text = directiveText.replace(
match[0],
`[[${resolvePath(templatePath, pageRefName)}]]`,
);
}
}
return true;
}
if (n.type === "WikiLinkPage") {
n.children![0].text = resolvePath(templatePath, n.children![0].text!);
return true;
}
return false;
});
}
export function cleanTemplateInstantiations(text: string) {
return text.replaceAll(directiveRegex, (
_fullMatch,