Tweaking the hashtag parser
parent
60cfefbc95
commit
2a4ea9b3e1
|
@ -3,7 +3,7 @@ syntax:
|
||||||
Hashtag:
|
Hashtag:
|
||||||
firstCharacters:
|
firstCharacters:
|
||||||
- "#"
|
- "#"
|
||||||
regex: "#[^#\\s]+"
|
regex: "#[^#\\d\\s]+\\w"
|
||||||
styles:
|
styles:
|
||||||
color: blue
|
color: blue
|
||||||
NakedURL:
|
NakedURL:
|
||||||
|
@ -89,6 +89,10 @@ functions:
|
||||||
path: "./tags.ts:tagComplete"
|
path: "./tags.ts:tagComplete"
|
||||||
events:
|
events:
|
||||||
- page:complete
|
- page:complete
|
||||||
|
tagProvider:
|
||||||
|
path: "./tags.ts:tagProvider"
|
||||||
|
events:
|
||||||
|
- query:tag
|
||||||
|
|
||||||
# Full text search
|
# Full text search
|
||||||
searchIndex:
|
searchIndex:
|
||||||
|
|
|
@ -5,10 +5,11 @@ import {
|
||||||
} from "@silverbulletmd/plugos-silverbullet-syscall";
|
} from "@silverbulletmd/plugos-silverbullet-syscall";
|
||||||
import { matchBefore } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
import { matchBefore } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
||||||
import type { IndexTreeEvent } from "@silverbulletmd/web/app_event";
|
import type { IndexTreeEvent } from "@silverbulletmd/web/app_event";
|
||||||
|
import { applyQuery, QueryProviderEvent } from "../query/engine";
|
||||||
import { removeQueries } from "../query/util";
|
import { removeQueries } from "../query/util";
|
||||||
|
|
||||||
// Key space
|
// Key space
|
||||||
// ht:TAG => true (for completion)
|
// tag:TAG => true (for completion)
|
||||||
|
|
||||||
export async function indexTags({ name, tree }: IndexTreeEvent) {
|
export async function indexTags({ name, tree }: IndexTreeEvent) {
|
||||||
removeQueries(tree);
|
removeQueries(tree);
|
||||||
|
@ -18,7 +19,7 @@ export async function indexTags({ name, tree }: IndexTreeEvent) {
|
||||||
});
|
});
|
||||||
batchSet(
|
batchSet(
|
||||||
name,
|
name,
|
||||||
[...allTags].map((t) => ({ key: `ht:${t}`, value: t }))
|
[...allTags].map((t) => ({ key: `tag:${t}`, value: t }))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ export async function tagComplete() {
|
||||||
if (!prefix) {
|
if (!prefix) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
let allTags = await queryPrefix(`ht:${prefix.text}`);
|
let allTags = await queryPrefix(`tag:${prefix.text}`);
|
||||||
return {
|
return {
|
||||||
from: prefix.from,
|
from: prefix.from,
|
||||||
options: allTags.map((tag) => ({
|
options: allTags.map((tag) => ({
|
||||||
|
@ -37,3 +38,26 @@ export async function tagComplete() {
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Tag = {
|
||||||
|
name: string;
|
||||||
|
freq: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function tagProvider({ query }: QueryProviderEvent) {
|
||||||
|
let allTags = new Map<string, number>();
|
||||||
|
for (let { value } of await queryPrefix("tag:")) {
|
||||||
|
let currentFreq = allTags.get(value);
|
||||||
|
if (!currentFreq) {
|
||||||
|
currentFreq = 0;
|
||||||
|
}
|
||||||
|
allTags.set(value, currentFreq + 1);
|
||||||
|
}
|
||||||
|
return applyQuery(
|
||||||
|
query,
|
||||||
|
[...allTags.entries()].map(([name, freq]) => ({
|
||||||
|
name,
|
||||||
|
freq,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ export async function indexTasks({ name, tree }: IndexTreeEvent) {
|
||||||
key: `task:${n.from}`,
|
key: `task:${n.from}`,
|
||||||
value: task,
|
value: task,
|
||||||
});
|
});
|
||||||
console.log("Task", task);
|
// console.log("Task", task);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Found", tasks.length, "task(s)");
|
console.log("Found", tasks.length, "task(s)");
|
||||||
|
|
Loading…
Reference in New Issue