From 6779c9076a50f4eff100725ea8e845aafa88dae7 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 25 Nov 2022 16:10:18 +0100 Subject: [PATCH] Stop replacing directives with garbag on silverbullet.md --- plugs/directive/command.ts | 19 +++++++++++++++++-- plugs/directive/directive.plug.yaml | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/plugs/directive/command.ts b/plugs/directive/command.ts index b80a104..74ef2ba 100644 --- a/plugs/directive/command.ts +++ b/plugs/directive/command.ts @@ -35,6 +35,14 @@ export async function updateDirectivesOnPageCommand(arg: any) { // Collect all directives and their body replacements const replacements: { fullMatch: string; text?: string }[] = []; + // Sanity checking if the server gives useful responses (will not be the case on silverbullet.md) + try { + await system.invokeFunction("server", "serverPing"); + } catch { + console.warn("Server not functional, not updating directives"); + return; + } + await replaceAsync( text, directiveRegex, @@ -56,9 +64,12 @@ export async function updateDirectivesOnPageCommand(arg: any) { fullMatch, ); replacement.text = replacementText; - return replacementText; + // Return value is ignored, we're using the replacements array + return fullMatch; } catch (e: any) { - return `${startInst}\n**ERROR:** ${e.message}\n${endInst}`; + replacement.text = `${startInst}\n**ERROR:** ${e.message}\n${endInst}`; + // Return value is ignored, we're using the replacements array + return fullMatch; } }, ); @@ -95,6 +106,10 @@ export async function updateDirectivesOnPageCommand(arg: any) { } } +export function serverPing() { + return "pong"; +} + // Called from client, running on server // The text passed here is going to be a single directive block (not a full page) export function serverRenderDirective( diff --git a/plugs/directive/directive.plug.yaml b/plugs/directive/directive.plug.yaml index be14fe6..335ccec 100644 --- a/plugs/directive/directive.plug.yaml +++ b/plugs/directive/directive.plug.yaml @@ -11,6 +11,9 @@ functions: key: "Alt-q" events: - editor:pageLoaded + serverPing: + env: server + path: ./command.ts:serverPing indexData: path: ./data.ts:indexData events: