Tags redo (#624)

Introduction of `tag` and `itags`
This commit is contained in:
Zef Hemel
2024-01-11 13:20:50 +01:00
committed by GitHub
parent 9a07c4c90a
commit 848211120c
31 changed files with 286 additions and 170 deletions
+11 -6
View File
@@ -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,
+1 -5
View File
@@ -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: