Attributes now have YAML values

This commit is contained in:
Zef Hemel
2023-07-26 17:12:56 +02:00
parent 5481e49393
commit 7b8d8af2c1
12 changed files with 139 additions and 54 deletions
+5 -5
View File
@@ -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
View File
@@ -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
View File
@@ -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)");