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 {
|
||||
const queryAST = parseTreeToAST(
|
||||
await language.parseLanguage("query", bodyText),
|
||||
);
|
||||
const parsedQuery = astToKvQuery(
|
||||
JSON.parse(
|
||||
await replaceTemplateVars(JSON.stringify(queryAST[1]), pageMeta),
|
||||
await language.parseLanguage(
|
||||
"query",
|
||||
await replaceTemplateVars(bodyText, pageMeta),
|
||||
),
|
||||
);
|
||||
const parsedQuery = astToKvQuery(queryAST[1]);
|
||||
|
||||
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 { renderMarkdownToHtml } from "../markdown/markdown_render.ts";
|
||||
import { prepareJS, wrapHTML } from "./util.ts";
|
||||
import { replaceTemplateVars } from "../template/template.ts";
|
||||
|
||||
type TemplateConfig = {
|
||||
// Pull the template from a page
|
||||
@ -29,11 +30,17 @@ export async function widget(bodyText: string): Promise<WidgetContent> {
|
||||
templateText = await space.readPage(templatePage);
|
||||
}
|
||||
|
||||
const value = config.value
|
||||
? JSON.parse(
|
||||
await replaceTemplateVars(JSON.stringify(config.value), pageMeta),
|
||||
)
|
||||
: undefined;
|
||||
|
||||
const rendered = config.raw
|
||||
? templateText
|
||||
: await handlebars.renderTemplate(
|
||||
templateText,
|
||||
config.value,
|
||||
value,
|
||||
{
|
||||
page: pageMeta,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user