diff --git a/plugs/index/api.ts b/plugs/index/api.ts index 3233330..6d2fdc4 100644 --- a/plugs/index/api.ts +++ b/plugs/index/api.ts @@ -176,6 +176,6 @@ export async function objectSourceProvider({ export async function discoverSources() { return (await datastore.query({ prefix: [indexKey, "tag"] })).map(( - { key }, - ) => key[2]); + { value }, + ) => value.name); } diff --git a/plugs/index/item.ts b/plugs/index/item.ts index 44c93b3..cfe9205 100644 --- a/plugs/index/item.ts +++ b/plugs/index/item.ts @@ -32,6 +32,8 @@ export async function indexItems({ name, tree }: IndexTreeEvent) { continue; } + const tags = new Set(["item"]); + const item: ItemObject = { ref: `${name}@${n.from}`, tags: [], @@ -44,7 +46,7 @@ export async function indexItems({ name, tree }: IndexTreeEvent) { collectNodesOfType(n, "Hashtag").forEach((h) => { // Push tag to the list, removing the initial # - item.tags.push(h.children![0].text!.substring(1)); + tags.add(h.children![0].text!.substring(1)); }); for (const child of n.children!.slice(1)) { @@ -62,11 +64,9 @@ export async function indexItems({ name, tree }: IndexTreeEvent) { } item.name = textNodes.map(renderToText).join("").trim(); + item.tags = [...tags.values()]; - if (item.tags.length > 0) { - // Only index items with tags - items.push(item); - } + items.push(item); } // console.log("Found", items, "item(s)"); await indexObjects(name, items); diff --git a/plugs/index/paragraph.ts b/plugs/index/paragraph.ts index ee2c28f..8933c5f 100644 --- a/plugs/index/paragraph.ts +++ b/plugs/index/paragraph.ts @@ -8,15 +8,16 @@ import { traverseTreeAsync, } from "$sb/lib/tree.ts"; import { extractAttributes } from "$sb/lib/attribute.ts"; +import { ObjectValue } from "$sb/types.ts"; /** ParagraphObject An index object for the top level text nodes */ -export type ParagraphObject = { - ref: string; - tags: string[]; - text: string; - page: string; - pos: number; -} & Record; +export type ParagraphObject = ObjectValue< + { + text: string; + page: string; + pos: number; + } & Record +>; export async function indexParagraphs({ name: page, tree }: IndexTreeEvent) { const objects: ParagraphObject[] = []; diff --git a/plugs/index/tags.ts b/plugs/index/tags.ts index 7ad853e..1b66545 100644 --- a/plugs/index/tags.ts +++ b/plugs/index/tags.ts @@ -43,7 +43,7 @@ export async function indexTags({ name, tree }: IndexTreeEvent) { [...tags].map((tag) => { const [tagName, parent] = tag.split(":"); return { - ref: tagName, + ref: tag, tags: ["tag"], name: tagName, page: name,