From 928614c7244c84e94d3a537a7155a24f965ab830 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Thu, 25 Jan 2024 12:06:01 +0100 Subject: [PATCH] Fixes #649 --- plugs/template/template_block.ts | 12 ++++++------ website/Live Templates.md | 6 ++---- website/Plugs/Ghost.md | 3 +-- website/Plugs/Git.md | 3 +-- website/Plugs/Github.md | 3 +-- website/Plugs/KaTeX.md | 3 +-- website/Plugs/Mattermost.md | 3 +-- website/Plugs/Mermaid.md | 3 +-- website/Plugs/Serendipity.md | 3 +-- website/Plugs/Twitter.md | 3 +-- website/internal/test page.md | 1 + 11 files changed, 17 insertions(+), 26 deletions(-) create mode 100644 website/internal/test page.md diff --git a/plugs/template/template_block.ts b/plugs/template/template_block.ts index e0cee27..12849d7 100644 --- a/plugs/template/template_block.ts +++ b/plugs/template/template_block.ts @@ -10,6 +10,8 @@ import { parseQuery } from "$sb/lib/parse-query.ts"; type TemplateWidgetConfig = { // Pull the template from a page page?: string; + // Include a page raw (without template processing) + raw?: string; // Or use a string directly template?: string; // To feed data into the template you can either use a concrete value @@ -17,9 +19,6 @@ type TemplateWidgetConfig = { // Or a query query?: string; - - // If true, don't render the template, just use it as-is - raw?: boolean; }; export async function widget( @@ -31,7 +30,8 @@ export async function widget( try { const config: TemplateWidgetConfig = await YAML.parse(bodyText); let templateText = config.template || ""; - let templatePage = config.page; + let templatePage = config.page || + (typeof config.raw !== "boolean" && config.raw); if (templatePage) { // Rewrite federation page references templatePage = rewritePageRefsInString(templatePage, pageName); @@ -39,13 +39,13 @@ export async function widget( templatePage = templatePage.slice(2, -2); } if (!templatePage) { - throw new Error("No template page specified"); + throw new Error("No page specified"); } try { templateText = await space.readPage(templatePage); } catch (e: any) { if (e.message === "Not found") { - throw new Error(`Template page ${templatePage} not found`); + throw new Error(`Page "${templatePage}" not found`); } } } diff --git a/website/Live Templates.md b/website/Live Templates.md index 459358d..841fd61 100644 --- a/website/Live Templates.md +++ b/website/Live Templates.md @@ -34,9 +34,7 @@ template: | {{/each}} ``` -If you just want to render the raw markdown without handling it as a handlebars template, set `raw` to true: +If you want to include another _page_ (not necessarily a template) unprocessed (so without replacing template placeholders), you can use `raw`: ```template -template: | - This is not going to be {{processed}} by Handlebars -raw: true +raw: "[[internal/test page]]" ``` diff --git a/website/Plugs/Ghost.md b/website/Plugs/Ghost.md index 50542db..303508e 100644 --- a/website/Plugs/Ghost.md +++ b/website/Plugs/Ghost.md @@ -7,6 +7,5 @@ share-support: true --- ```template -page: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-ghost/main/README]]" -raw: true +raw: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-ghost/main/README]]" ``` \ No newline at end of file diff --git a/website/Plugs/Git.md b/website/Plugs/Git.md index 993dc87..bc4b6a8 100644 --- a/website/Plugs/Git.md +++ b/website/Plugs/Git.md @@ -6,6 +6,5 @@ author: Zef Hemel --- ```template -page: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-git/main/README]]" -raw: true +raw: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-git/main/README]]" ``` \ No newline at end of file diff --git a/website/Plugs/Github.md b/website/Plugs/Github.md index 35ba342..dd348a6 100644 --- a/website/Plugs/Github.md +++ b/website/Plugs/Github.md @@ -7,6 +7,5 @@ tags: plug --- ```template -page: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-github/main/README]]" -raw: true +raw: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-github/main/README]]" ``` \ No newline at end of file diff --git a/website/Plugs/KaTeX.md b/website/Plugs/KaTeX.md index b06ea30..f45bf82 100644 --- a/website/Plugs/KaTeX.md +++ b/website/Plugs/KaTeX.md @@ -7,6 +7,5 @@ author: Zef Hemel --- ```template -page: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-katex/main/README]]" -raw: true +raw: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-katex/main/README]]" ``` \ No newline at end of file diff --git a/website/Plugs/Mattermost.md b/website/Plugs/Mattermost.md index 66e5ee7..855d1c1 100644 --- a/website/Plugs/Mattermost.md +++ b/website/Plugs/Mattermost.md @@ -10,6 +10,5 @@ tags: plug ```template -page: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-mattermost/main/README]]" -raw: true +raw: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-mattermost/main/README]]" ``` \ No newline at end of file diff --git a/website/Plugs/Mermaid.md b/website/Plugs/Mermaid.md index 351436e..3357fb0 100644 --- a/website/Plugs/Mermaid.md +++ b/website/Plugs/Mermaid.md @@ -12,6 +12,5 @@ flowchart TD ``` ```template -page: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-mermaid/main/README]]" -raw: true +raw: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-mermaid/main/README]]" ``` \ No newline at end of file diff --git a/website/Plugs/Serendipity.md b/website/Plugs/Serendipity.md index 347baa6..3027f3b 100644 --- a/website/Plugs/Serendipity.md +++ b/website/Plugs/Serendipity.md @@ -6,6 +6,5 @@ tags: plug --- ```template -page: "[[!raw.githubusercontent.com/m1lt0n/silverbullet-serendipity/main/README]]" -raw: true +raw: "[[!raw.githubusercontent.com/m1lt0n/silverbullet-serendipity/main/README]]" ``` \ No newline at end of file diff --git a/website/Plugs/Twitter.md b/website/Plugs/Twitter.md index f892f24..796414b 100644 --- a/website/Plugs/Twitter.md +++ b/website/Plugs/Twitter.md @@ -8,6 +8,5 @@ author: SilverBullet Authors Remember Twitter? ```template -page: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-twitter/main/README]]" -raw: true +raw: "[[!raw.githubusercontent.com/silverbulletmd/silverbullet-twitter/main/README]]" ``` \ No newline at end of file diff --git a/website/internal/test page.md b/website/internal/test page.md new file mode 100644 index 0000000..81794b2 --- /dev/null +++ b/website/internal/test page.md @@ -0,0 +1 @@ +This is a simple test page \ No newline at end of file