Fix index.defineTag after refactor

This commit is contained in:
Zef Hemel
2025-06-17 10:46:38 +02:00
parent de561cdf6c
commit aff178bd78
5 changed files with 49 additions and 18 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ config.define("tagDefinitions", {
type = "object",
properties = {
schema = { type = "object" },
metatable = { type = "object" },
metatable = { },
},
},
})
+1 -1
View File
@@ -15,7 +15,7 @@ export function eventListenerSyscalls(
_ctx,
def: EventSubscription,
) => {
console.log("Registering Lua event listener: ", def.name);
// console.log("Registering Lua event listener: ", def.name);
const listeners = client.config.get<Function[]>([
"eventListeners",
def.name,
+13 -15
View File
@@ -7,16 +7,11 @@ import {
jsToLuaValue,
type LuaEnv,
type LuaStackFrame,
type LuaTable,
} from "../../lib/space_lua/runtime.ts";
import type { Client } from "../client.ts";
type TagDef = {
name: string;
schema?: any;
metatable?: any;
};
export function indexSyscalls(client: Client): SysCallMapping {
return {
"index.tag": (_ctx, tagName: string): LuaQueryCollection => {
@@ -33,26 +28,29 @@ export function indexSyscalls(client: Client): SysCallMapping {
sf,
(key, value: any) => {
const tag = key[1];
const tagDef = client.config.get<Record<string, TagDef>>(
"tagDefinitions",
{},
)[tag];
if (!tagDef) {
const tagDef = client.config.get<LuaTable | undefined>(
["tagDefinitions", tag],
undefined,
);
if (!tagDef || !tagDef.has("metatable")) {
// Return as is
return value;
}
console.log("Found this tagDef", tagDef);
// Convert to LuaTable
value = jsToLuaValue(value);
value.metatable = tagDef.metatable;
value.metatable = tagDef.get("metatable");
return value;
},
);
},
};
},
"index.defineTag": (_ctx, tagDef: TagDef) => {
client.config.set(tagDef.name, tagDef);
"lua:index.defineTag": (_ctx, tagDef: LuaTable) => {
// Using 'lua:' prefix to _not_ convert tagDef to a JS version (but keep original LuaTable)
if (!tagDef.has("name")) {
throw new Error("A tag name is required");
}
client.config.set(["tagDefinitions", tagDef.get("name")], tagDef);
},
};
}
+21 -1
View File
@@ -59,4 +59,24 @@ The `extractOptions` is an optional table that can contain the following keys (w
- `removeFrontmatterSection`: A boolean to remove the frontmatter section from the document.
Example applied to this page:
${(index.extractFrontmatter(editor.getText())).frontmatter}
${(index.extractFrontmatter(editor.getText())).frontmatter}
## index.defineTag(def)
Allows you to attach a custom Lua metatable to objects part of a particular tag.
### Example
The following adds a custom attribute to all page objects that dynamically produces an ALL CAPS version of the page name:
```space-lua
index.defineTag {
name = "page",
metatable = {
__index = function(self, attr)
if attr == "loudName" then
return string.upper(self.name)
end
end
}
}
```
In use:
${query[[from index.tag "page" select {name=_.name, loudName=_.loudName} limit 3]]}
+13
View File
@@ -1,3 +1,16 @@
# Introduction
SilverBullet is a tool to **keep, organize, and structure your personal knowledge** and to make it **universally accessible** across all your devices.
It stores your content as a collection of [[Pages]] (called a [[Spaces|Space]]) as [[Markdown]] files on disk. It enables [[Links|Linking]], [[Tags|Tagging]] and **annotating** with [[Metadata]] at various levels. These annotations let you treat your space as a [[Objects|database]], enabling you to [[Space Lua/Lua Integrated Query|Query]] it in interesting ways.
SilverBullet is a deeply **programmable** and **personalizable** environment. Using [[Space Lua]] (its custom [[Lua]] implementation), you can dynamically generate part of your pages using [[Space Lua/Lua Integrated Query|Queries]] and other [[Space Lua|Expressions]], create custom [[Commands]] and [[Space Lua/Widgets]]. [[Space Style]] allows you to tweak your Space’s look and feel using CSS.
You [[Install|self host]] SilverBullet on a server under your control. It is deployable as a single [[Install/Binary]] or [[Install/Docker]] container. _You_ decide if you run it locally, in your VPN, or on the cloud.
The SilverBullet client is built as a [[Local First]], progressive web application, syncing all your content into your browser’s IndexedDB, enabling you **instant access** to your entire space no matter if you are **online or offline**.
---
# Introduction
SilverBullet is an open source **personal productivity platform** built on [[Markdown]], turbo charged with the scripting power of [[Space Lua|Lua]]. You [[Install|self host]] it on your server, access it via any modern browser on any device (desktop, laptop, mobile). Since SilverBullet is built as a [[Local First]] [[PWA]], it is fully offline capable. Temporarily don’t have network access? No problem, SilverBullet will sync your content when you get back online.