Index .lua files in your space as space lua scripts
parent
ccea2200ac
commit
94acad1a9b
|
@ -60,6 +60,11 @@ functions:
|
|||
events:
|
||||
- attachment:index
|
||||
|
||||
indexSpaceLuaFile:
|
||||
path: "./script.ts:indexSpaceLuaFile"
|
||||
events:
|
||||
- attachment:index
|
||||
|
||||
indexPage:
|
||||
path: page.ts:indexPage
|
||||
events:
|
||||
|
|
|
@ -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),
|
||||
}]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue