Fixed using handlebar variables live queries and templates
This commit is contained in:
parent
ba3f9f5b2c
commit
ae3e5f375e
@ -12,13 +12,12 @@ export async function widget(bodyText: string): Promise<WidgetContent> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const queryAST = parseTreeToAST(
|
const queryAST = parseTreeToAST(
|
||||||
await language.parseLanguage("query", bodyText),
|
await language.parseLanguage(
|
||||||
);
|
"query",
|
||||||
const parsedQuery = astToKvQuery(
|
await replaceTemplateVars(bodyText, pageMeta),
|
||||||
JSON.parse(
|
|
||||||
await replaceTemplateVars(JSON.stringify(queryAST[1]), pageMeta),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
const parsedQuery = astToKvQuery(queryAST[1]);
|
||||||
|
|
||||||
const eventName = `query:${parsedQuery.querySource}`;
|
const eventName = `query:${parsedQuery.querySource}`;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { editor, handlebars, markdown, space, YAML } from "$sb/syscalls.ts";
|
|||||||
import { rewritePageRefs } from "$sb/lib/resolve.ts";
|
import { rewritePageRefs } from "$sb/lib/resolve.ts";
|
||||||
import { renderMarkdownToHtml } from "../markdown/markdown_render.ts";
|
import { renderMarkdownToHtml } from "../markdown/markdown_render.ts";
|
||||||
import { prepareJS, wrapHTML } from "./util.ts";
|
import { prepareJS, wrapHTML } from "./util.ts";
|
||||||
|
import { replaceTemplateVars } from "../template/template.ts";
|
||||||
|
|
||||||
type TemplateConfig = {
|
type TemplateConfig = {
|
||||||
// Pull the template from a page
|
// Pull the template from a page
|
||||||
@ -29,11 +30,17 @@ export async function widget(bodyText: string): Promise<WidgetContent> {
|
|||||||
templateText = await space.readPage(templatePage);
|
templateText = await space.readPage(templatePage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const value = config.value
|
||||||
|
? JSON.parse(
|
||||||
|
await replaceTemplateVars(JSON.stringify(config.value), pageMeta),
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const rendered = config.raw
|
const rendered = config.raw
|
||||||
? templateText
|
? templateText
|
||||||
: await handlebars.renderTemplate(
|
: await handlebars.renderTemplate(
|
||||||
templateText,
|
templateText,
|
||||||
config.value,
|
value,
|
||||||
{
|
{
|
||||||
page: pageMeta,
|
page: pageMeta,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user