1
0

Fix hashtag parsing bug, re-added item indexing

This commit is contained in:
Zef Hemel 2022-07-08 09:50:26 +02:00
parent cce5be43e1
commit ca86f75e16
2 changed files with 32 additions and 7 deletions

View File

@ -3,7 +3,7 @@ syntax:
Hashtag: Hashtag:
firstCharacters: firstCharacters:
- "#" - "#"
regex: "#[^#\\d\\s]+\\w" regex: "#[^#\\d\\s]+\\w+"
styles: styles:
color: blue color: blue
NakedURL: NakedURL:
@ -36,7 +36,6 @@ functions:
reindexSpace: reindexSpace:
path: "./page.ts:reindexSpace" path: "./page.ts:reindexSpace"
env: server env: server
deletePage: deletePage:
path: "./page.ts:deletePage" path: "./page.ts:deletePage"
command: command:
@ -63,6 +62,16 @@ functions:
events: events:
- page:complete - page:complete
# Item indexing
indexItem:
path: "./item.ts:indexItems"
events:
- page:index
itemQueryProvider:
path: "./item.ts:queryProvider"
events:
- query:item
# Navigation # Navigation
linkNavigate: linkNavigate:
path: "./navigate.ts:linkNavigate" path: "./navigate.ts:linkNavigate"

View File

@ -5,9 +5,11 @@ import {
queryPrefix, queryPrefix,
} from "@silverbulletmd/plugos-silverbullet-syscall/index"; } from "@silverbulletmd/plugos-silverbullet-syscall/index";
import { import {
collectNodesMatching,
collectNodesOfType, collectNodesOfType,
ParseTree, ParseTree,
renderToText, renderToText,
replaceNodesMatching,
} from "@silverbulletmd/common/tree"; } from "@silverbulletmd/common/tree";
import { removeQueries } from "../query/util"; import { removeQueries } from "../query/util";
import { applyQuery, QueryProviderEvent } from "../query/engine"; import { applyQuery, QueryProviderEvent } from "../query/engine";
@ -15,6 +17,7 @@ import { applyQuery, QueryProviderEvent } from "../query/engine";
export type Item = { export type Item = {
name: string; name: string;
nested?: string; nested?: string;
tags?: string[];
// Not stored in DB // Not stored in DB
page?: string; page?: string;
pos?: number; pos?: number;
@ -32,6 +35,11 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
if (!n.children) { if (!n.children) {
return; return;
} }
if (collectNodesOfType(n, "Task").length > 0) {
// This is a task item, skip it
return;
}
let textNodes: ParseTree[] = []; let textNodes: ParseTree[] = [];
let nested: string | undefined; let nested: string | undefined;
for (let child of n.children!.slice(1)) { for (let child of n.children!.slice(1)) {
@ -41,16 +49,24 @@ export async function indexItems({ name, tree }: IndexTreeEvent) {
} }
textNodes.push(child); textNodes.push(child);
} }
let item = textNodes.map(renderToText).join("").trim();
let value: Item = { let itemText = textNodes.map(renderToText).join("").trim();
name: item, let item: Item = {
name: itemText,
}; };
if (nested) { if (nested) {
value.nested = nested; item.nested = nested;
} }
collectNodesOfType(n, "Hashtag").forEach((h) => {
if (!item.tags) {
item.tags = [];
}
item.tags.push(h.children![0].text!);
});
items.push({ items.push({
key: `it:${n.from}`, key: `it:${n.from}`,
value, value: item,
}); });
}); });
console.log("Found", items.length, "item(s)"); console.log("Found", items.length, "item(s)");