Fixes #649
This commit is contained in:
parent
8404256ccb
commit
928614c724
@ -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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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]]"
|
||||
```
|
||||
|
@ -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]]"
|
||||
```
|
@ -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]]"
|
||||
```
|
@ -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]]"
|
||||
```
|
@ -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]]"
|
||||
```
|
@ -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]]"
|
||||
```
|
@ -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]]"
|
||||
```
|
@ -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]]"
|
||||
```
|
@ -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]]"
|
||||
```
|
1
website/internal/test page.md
Normal file
1
website/internal/test page.md
Normal file
@ -0,0 +1 @@
|
||||
This is a simple test page
|
Loading…
Reference in New Issue
Block a user