Preparing for 0.5.6

This commit is contained in:
Zef Hemel
2023-11-19 12:18:16 +01:00
parent 7503110e84
commit 063c49effb
9 changed files with 59 additions and 23 deletions
+34 -1
View File
@@ -4,6 +4,8 @@ import { resolvePath } from "$sb/lib/resolve.ts";
import { indexObjects, queryObjects } from "./api.ts";
import { ObjectValue } from "$sb/types.ts";
const pageRefRegex = /\[\[([^\]]+)\]\]/g;
export type LinkObject = {
ref: string;
tags: string[];
@@ -123,9 +125,40 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
links.push(link);
return true;
}
// Also index links used inside query and template fenced code blocks
if (n.type === "FencedCode") {
const codeInfo = findNodeOfType(n, "CodeInfo")!;
if (!codeInfo) {
return false;
}
const codeLang = codeInfo.children![0].text!;
if (codeLang === "template" || codeLang === "query") {
const codeText = findNodeOfType(n, "CodeText");
if (!codeText) {
return false;
}
const code = codeText.children![0].text!;
const matches = code.matchAll(pageRefRegex);
for (const match of matches) {
const pageRefName = resolvePath(name, match[1]);
const pos = codeText.from! + match.index! + 2;
links.push({
ref: `${name}@${pos}`,
tags: ["link"],
toPage: pageRefName,
page: name,
snippet: extractSnippet(pageText, pos),
pos: pos,
asTemplate: true,
inDirective: false,
});
}
}
}
return false;
});
// console.log("Found", backLinks, "page link(s)");
// console.log("Found", links, "page link(s)");
await indexObjects(name, links);
}
+3
View File
@@ -33,6 +33,9 @@ export async function widget(
if (templatePage.startsWith("[[")) {
templatePage = templatePage.slice(2, -2);
}
if (!templatePage) {
throw new Error("No template page specified");
}
templateText = await space.readPage(templatePage);
}