Attributes now have YAML values
This commit is contained in:
+5
-5
@@ -22,13 +22,13 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
|
||||
|
||||
const coll = collectNodesOfType(tree, "ListItem");
|
||||
|
||||
coll.forEach((n) => {
|
||||
for (const n of coll) {
|
||||
if (!n.children) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
if (collectNodesOfType(n, "Task").length > 0) {
|
||||
// This is a task item, skip it
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
const item: Item = {
|
||||
@@ -43,7 +43,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
|
||||
break;
|
||||
}
|
||||
// Extract attributes and remove from tree
|
||||
const extractedAttributes = extractAttributes(child, true);
|
||||
const extractedAttributes = await extractAttributes(child, true);
|
||||
for (const [key, value] of Object.entries(extractedAttributes)) {
|
||||
item[key] = value;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
|
||||
key: `it:${n.from}`,
|
||||
value: item,
|
||||
});
|
||||
});
|
||||
}
|
||||
// console.log("Found", items.length, "item(s)");
|
||||
await index.batchSet(name, items);
|
||||
}
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
|
||||
// [[Style Links]]
|
||||
// console.log("Now indexing links for", name);
|
||||
const pageMeta = await extractFrontmatter(tree);
|
||||
const toplevelAttributes = extractAttributes(tree, false);
|
||||
const toplevelAttributes = await extractAttributes(tree, false);
|
||||
if (
|
||||
Object.keys(pageMeta).length > 0 ||
|
||||
Object.keys(toplevelAttributes).length > 0
|
||||
|
||||
+8
-2
@@ -14,12 +14,14 @@ import {
|
||||
import {
|
||||
addParentPointers,
|
||||
collectNodesMatching,
|
||||
collectNodesMatchingAsync,
|
||||
collectNodesOfType,
|
||||
findNodeOfType,
|
||||
nodeAtPos,
|
||||
ParseTree,
|
||||
renderToText,
|
||||
replaceNodesMatching,
|
||||
traverseTreeAsync,
|
||||
} from "$sb/lib/tree.ts";
|
||||
import { applyQuery, removeQueries } from "$sb/lib/query.ts";
|
||||
import { niceDate } from "$sb/lib/dates.ts";
|
||||
@@ -44,7 +46,10 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
const tasks: { key: string; value: Task }[] = [];
|
||||
removeQueries(tree);
|
||||
addParentPointers(tree);
|
||||
collectNodesOfType(tree, "Task").forEach((n) => {
|
||||
await traverseTreeAsync(tree, async (n) => {
|
||||
if (n.type !== "Task") {
|
||||
return false;
|
||||
}
|
||||
const complete = n.children![0].children![0].text! !== "[ ]";
|
||||
const task: Task = {
|
||||
name: "",
|
||||
@@ -69,7 +74,7 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
});
|
||||
|
||||
// Extract attributes and remove from tree
|
||||
const extractedAttributes = extractAttributes(n, true);
|
||||
const extractedAttributes = await extractAttributes(n, true);
|
||||
for (const [key, value] of Object.entries(extractedAttributes)) {
|
||||
task[key] = value;
|
||||
}
|
||||
@@ -85,6 +90,7 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
key: `task:${n.from}`,
|
||||
value: task,
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
// console.log("Found", tasks.length, "task(s)");
|
||||
|
||||
Reference in New Issue
Block a user