Robustness and federation sync
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user