Federation: rewrite page references in federated content
This commit is contained in:
+3
-1
@@ -4,6 +4,7 @@ import { index } from "$sb/silverbullet-syscall/mod.ts";
|
||||
import { collectNodesOfType, ParseTree, renderToText } from "$sb/lib/tree.ts";
|
||||
import { applyQuery, removeQueries } from "$sb/lib/query.ts";
|
||||
import { extractAttributes } from "$sb/lib/attribute.ts";
|
||||
import { rewritePageRefs } from "$sb/lib/resolve.ts";
|
||||
|
||||
export type Item = {
|
||||
name: string;
|
||||
@@ -38,6 +39,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
|
||||
const textNodes: ParseTree[] = [];
|
||||
let nested: string | undefined;
|
||||
for (const child of n.children!.slice(1)) {
|
||||
rewritePageRefs(child, name);
|
||||
if (child.type === "OrderedList" || child.type === "BulletList") {
|
||||
nested = renderToText(child);
|
||||
break;
|
||||
@@ -67,7 +69,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
|
||||
value: item,
|
||||
});
|
||||
}
|
||||
// console.log("Found", items.length, "item(s)");
|
||||
// console.log("Found", items, "item(s)");
|
||||
await index.batchSet(name, items);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ import { events } from "$sb/plugos-syscall/mod.ts";
|
||||
|
||||
import { applyQuery } from "$sb/lib/query.ts";
|
||||
import { invokeFunction } from "$sb/silverbullet-syscall/system.ts";
|
||||
import { backlinkPrefix } from "./page_links.ts";
|
||||
|
||||
// Key space:
|
||||
// meta: => metaJson
|
||||
|
||||
@@ -4,6 +4,7 @@ import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
|
||||
import { extractAttributes } from "$sb/lib/attribute.ts";
|
||||
import { IndexTreeEvent, QueryProviderEvent } from "$sb/app_event.ts";
|
||||
import { applyQuery } from "$sb/lib/query.ts";
|
||||
import { resolvePath } from "$sb/lib/resolve.ts";
|
||||
|
||||
// Key space:
|
||||
// l:toPage:pos => {name: pageName, inDirective: true, asTemplate: true}
|
||||
@@ -46,7 +47,10 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
||||
directiveDepth++;
|
||||
const pageRef = findNodeOfType(n, "PageRef")!;
|
||||
if (pageRef) {
|
||||
const pageRefName = pageRef.children![0].text!.slice(2, -2);
|
||||
const pageRefName = resolvePath(
|
||||
name,
|
||||
pageRef.children![0].text!.slice(2, -2),
|
||||
);
|
||||
backLinks.push({
|
||||
key: `${backlinkPrefix}${pageRefName}:${pageRef.from! + 2}`,
|
||||
value: { name, asTemplate: true },
|
||||
@@ -57,7 +61,7 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
||||
if (directiveText) {
|
||||
const match = /\[\[(.+)\]\]/.exec(directiveText);
|
||||
if (match) {
|
||||
const pageRefName = match[1];
|
||||
const pageRefName = resolvePath(name, match[1]);
|
||||
backLinks.push({
|
||||
key: `${backlinkPrefix}${pageRefName}:${
|
||||
n.from! + match.index! + 2
|
||||
@@ -77,7 +81,7 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
||||
if (n.type === "WikiLink") {
|
||||
const wikiLinkPage = findNodeOfType(n, "WikiLinkPage")!;
|
||||
const wikiLinkAlias = findNodeOfType(n, "WikiLinkAlias");
|
||||
let toPage = wikiLinkPage.children![0].text!;
|
||||
let toPage = resolvePath(name, wikiLinkPage.children![0].text!);
|
||||
if (toPage.includes("@")) {
|
||||
toPage = toPage.split("@")[0];
|
||||
}
|
||||
@@ -96,7 +100,7 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
// console.log("Found", backLinks.length, "page link(s)");
|
||||
// console.log("Found", backLinks, "page link(s)");
|
||||
await index.batchSet(name, backLinks);
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -24,6 +24,7 @@ import {
|
||||
import { applyQuery, removeQueries } from "$sb/lib/query.ts";
|
||||
import { niceDate } from "$sb/lib/dates.ts";
|
||||
import { extractAttributes } from "$sb/lib/attribute.ts";
|
||||
import { rewritePageRefs } from "$sb/lib/resolve.ts";
|
||||
|
||||
export type Task = {
|
||||
name: string;
|
||||
@@ -54,6 +55,8 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
done: complete,
|
||||
};
|
||||
|
||||
rewritePageRefs(n, name);
|
||||
|
||||
replaceNodesMatching(n, (tree) => {
|
||||
if (tree.type === "DeadlineDate") {
|
||||
task.deadline = getDeadline(tree);
|
||||
@@ -91,7 +94,7 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
return true;
|
||||
});
|
||||
|
||||
// console.log("Found", tasks.length, "task(s)");
|
||||
// console.log("Found", tasks, "task(s)");
|
||||
await index.batchSet(name, tasks);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user