From 9ccfe138183ee6cf39f8f24a8863f1b14f80b46a Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Thu, 6 Feb 2025 08:36:43 +0100 Subject: [PATCH] Expose SB instance base URL to Lua --- common/space_lua/stdlib/space_lua.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/common/space_lua/stdlib/space_lua.ts b/common/space_lua/stdlib/space_lua.ts index 422707b1..4e3cfdce 100644 --- a/common/space_lua/stdlib/space_lua.ts +++ b/common/space_lua/stdlib/space_lua.ts @@ -135,4 +135,17 @@ export const spaceLuaApi = new LuaTable({ return interpolateLuaString(sf, template, envAugmentation); }, ), + /** + * Returns your SilverBullet instance's base URL, or `undefined` when run on the server + */ + base_url: new LuaBuiltinFunction( + () => { + // Deal with Deno + if (typeof location === "undefined") { + return null; + } else { + return location.protocol + "//" + location.host; + } + }, + ), });