Date indexer

This commit is contained in:
Zef Hemel
2022-04-10 11:04:07 +02:00
parent e8547604a1
commit d649009dd2
16 changed files with 1460 additions and 53 deletions
+9 -9
View File
@@ -24,14 +24,12 @@ functions:
reindexSpace:
path: "./page.ts:reindexSpace"
env: server
showBackLinks:
path: "./page.ts:showBackLinks"
command:
name: "Page: Back Links"
renamePage:
path: "./page.ts:renamePage"
command:
name: "Page: Rename"
mac: Cmd-Alt-r
key: Ctrl-Alt-r
pageComplete:
path: "./page.ts:pageComplete"
isCompleter: true
@@ -49,18 +47,20 @@ functions:
path: "./dates.ts:insertToday"
slashCommand:
name: today
welcome:
path: "./server.ts:welcome"
insertTomorrow:
path: "./dates.ts:insertTomorrow"
slashCommand:
name: tomorrow
indexDates:
path: "./dates.ts:indexDates"
events:
- plug:load
env: server
- page:index
updateMaterializedQueriesOnPage:
path: ./materialized_queries.ts:updateMaterializedQueriesOnPage
updateMaterializedQueriesCommand:
path: ./materialized_queries.ts:updateMaterializedQueriesCommand
command:
name: "Materialized Queries: Update"
parseCommand:
path: ./page.ts:parsePage
command:
+30 -2
View File
@@ -1,6 +1,34 @@
import { insertAtCursor } from "plugos-silverbullet-syscall/editor";
import { IndexEvent } from "../../webapp/app_event";
import { batchSet } from "plugos-silverbullet-syscall";
import { whiteOutQueries } from "./materialized_queries";
const dateMatchRegex = /(\d{4}\-\d{2}\-\d{2})/g;
// Index key space:
// d:[date]:page@pos
export async function indexDates({ name, text }: IndexEvent) {
let dates: { key: string; value: boolean }[] = [];
text = whiteOutQueries(text);
console.log("Now date indexing", name);
for (let match of text.matchAll(dateMatchRegex)) {
// console.log("Date match", match[0]);
dates.push({
key: `d:${match[0]}:${name}@${match.index}`,
value: true,
});
}
console.log("Found", dates.length, "dates");
await batchSet(name, dates);
}
export async function insertToday() {
let niceDate = new Date().toISOString().split("T")[0];
await insertAtCursor(niceDate);
await insertAtCursor(new Date().toISOString().split("T")[0]);
}
export async function insertTomorrow() {
let d = new Date();
d.setDate(d.getDate() + 1);
await insertAtCursor(d.toISOString().split("T")[0]);
}
+3 -7
View File
@@ -81,6 +81,9 @@ export async function renamePage() {
}
for (let pageToUpdate of pageToUpdateSet) {
if (pageToUpdate === oldName) {
continue;
}
console.log("Now going to update links in", pageToUpdate);
let { text } = await readPage(pageToUpdate);
// console.log("Received text", text);
@@ -133,13 +136,6 @@ async function getBackLinks(pageName: string): Promise<BackLink[]> {
return pagesToUpdate;
}
export async function showBackLinks() {
const pageName = await getCurrentPage();
let backLinks = await getBackLinks(pageName);
console.log("Backlinks", backLinks);
}
export async function reindexCommand() {
await flashNotification("Reindexing...");
await invokeFunction("server", "reindexSpace");
-8
View File
@@ -7,11 +7,3 @@ export function endpointTest(req: EndpointRequest): EndpointResponse {
body: "Hello world!",
};
}
export function welcome(plugName: string) {
if (plugName !== "core") {
return;
}
console.log("Hello world!!", plugName);
return "hi";
}