diff --git a/Library/Std/Config.md b/Library/Std/Config.md index 87ab042a..0fb42775 100644 --- a/Library/Std/Config.md +++ b/Library/Std/Config.md @@ -82,7 +82,7 @@ config.define("tagDefinitions", { type = "object", properties = { schema = { type = "object" }, - metatable = { type = "object" }, + metatable = { }, }, }, }) diff --git a/web/syscalls/event.ts b/web/syscalls/event.ts index c8216926..e2304e80 100644 --- a/web/syscalls/event.ts +++ b/web/syscalls/event.ts @@ -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([ "eventListeners", def.name, diff --git a/web/syscalls/index.ts b/web/syscalls/index.ts index b6212534..25767594 100644 --- a/web/syscalls/index.ts +++ b/web/syscalls/index.ts @@ -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>( - "tagDefinitions", - {}, - )[tag]; - if (!tagDef) { + const tagDef = client.config.get( + ["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); }, }; } diff --git a/website/API/index.md b/website/API/index.md index bb92a4f5..3e6ce932 100644 --- a/website/API/index.md +++ b/website/API/index.md @@ -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} \ No newline at end of file +${(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]]} diff --git a/website/SilverBullet.md b/website/SilverBullet.md index ab0a0476..d19d9a7d 100644 --- a/website/SilverBullet.md +++ b/website/SilverBullet.md @@ -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.