+11
-6
@@ -18,6 +18,8 @@ import { extractAttributes } from "$sb/lib/attribute.ts";
|
||||
import { rewritePageRefs } from "$sb/lib/resolve.ts";
|
||||
import { ObjectValue } from "$sb/types.ts";
|
||||
import { indexObjects, queryObjects } from "../index/plug_api.ts";
|
||||
import { updateITags } from "$sb/lib/tags.ts";
|
||||
import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
|
||||
|
||||
export type TaskObject = ObjectValue<
|
||||
{
|
||||
@@ -46,9 +48,8 @@ const incompleteStates = [" "];
|
||||
export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
const tasks: ObjectValue<TaskObject>[] = [];
|
||||
const taskStates = new Map<string, { count: number; firstPos: number }>();
|
||||
addParentPointers(tree);
|
||||
// const allAttributes: AttributeObject[] = [];
|
||||
// const allTags = new Set<string>();
|
||||
const frontmatter = await extractFrontmatter(tree);
|
||||
|
||||
await traverseTreeAsync(tree, async (n) => {
|
||||
if (n.type !== "Task") {
|
||||
return false;
|
||||
@@ -65,7 +66,7 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
const complete = completeStates.includes(state);
|
||||
const task: TaskObject = {
|
||||
ref: `${name}@${n.from}`,
|
||||
tags: [],
|
||||
tag: "task",
|
||||
name: "",
|
||||
done: complete,
|
||||
page: name,
|
||||
@@ -84,10 +85,12 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
if (tree.type === "Hashtag") {
|
||||
// Push the tag to the list, removing the initial #
|
||||
const tagName = tree.children![0].text!.substring(1);
|
||||
if (!task.tags) {
|
||||
task.tags = [];
|
||||
}
|
||||
task.tags.push(tagName);
|
||||
}
|
||||
});
|
||||
task.tags = ["task", ...task.tags];
|
||||
|
||||
// Extract attributes and remove from tree
|
||||
const extractedAttributes = await extractAttributes(n, true);
|
||||
@@ -97,6 +100,8 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
|
||||
task.name = n.children!.slice(1).map(renderToText).join("").trim();
|
||||
|
||||
updateITags(task, frontmatter);
|
||||
|
||||
tasks.push(task);
|
||||
return true;
|
||||
});
|
||||
@@ -107,7 +112,7 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||
name,
|
||||
Array.from(taskStates.entries()).map(([state, { firstPos, count }]) => ({
|
||||
ref: `${name}@${firstPos}`,
|
||||
tags: ["taskstate"],
|
||||
tag: "taskstate",
|
||||
state,
|
||||
count,
|
||||
page: name,
|
||||
|
||||
@@ -35,15 +35,11 @@ functions:
|
||||
indexTasks:
|
||||
path: "./task.ts:indexTasks"
|
||||
events:
|
||||
- page:index
|
||||
- page:index
|
||||
taskToggle:
|
||||
path: "./task.ts:taskToggle"
|
||||
events:
|
||||
- page:click
|
||||
# itemQueryProvider:
|
||||
# path: ./task.ts:queryProvider
|
||||
# events:
|
||||
# - query:task
|
||||
taskToggleCommand:
|
||||
path: ./task.ts:taskCycleCommand
|
||||
command:
|
||||
|
||||
Reference in New Issue
Block a user