Index .lua files in your space as space lua scripts

pull/1212/head
Zef Hemel 2025-01-16 12:35:34 +01:00
parent ccea2200ac
commit 94acad1a9b
2 changed files with 19 additions and 1 deletions

View File

@ -60,6 +60,11 @@ functions:
events:
- attachment:index
indexSpaceLuaFile:
path: "./script.ts:indexSpaceLuaFile"
events:
- attachment:index
indexPage:
path: page.ts:indexPage
events:

View File

@ -2,7 +2,7 @@ import type { IndexTreeEvent } from "../../plug-api/types.ts";
import { collectNodesOfType, findNodeOfType } from "../../plug-api/lib/tree.ts";
import type { ObjectValue } from "../../plug-api/types.ts";
import { indexObjects } from "./api.ts";
import { space } from "@silverbulletmd/silverbullet/syscalls";
export type ScriptObject = ObjectValue<{
script: string;
}>;
@ -58,3 +58,16 @@ export async function indexSpaceLua({ name, tree }: IndexTreeEvent) {
});
await indexObjects<ScriptObject>(name, allScripts);
}
export async function indexSpaceLuaFile(name: string) {
if (!name.endsWith(".lua")) {
return;
}
console.log("Indexing space lua file", name);
const data = await space.readFile(name);
await indexObjects<ScriptObject>(name, [{
ref: `${name}`,
tag: "space-lua",
script: new TextDecoder().decode(data),
}]);
}