Rebuilt frontmatter templates as template widgets

This commit is contained in:
Zef Hemel
2024-01-08 17:08:35 +01:00
parent 5b3dd500e4
commit 848e11a773
45 changed files with 471 additions and 483 deletions
+6 -1
View File
@@ -36,8 +36,13 @@ export async function expandCodeWidgets(
renderToText(codeTextNode!),
pageName,
);
if (!result) {
return {
text: "",
};
}
// Only do this for "markdown" widgets, that is: that can render to markdown
if (result.markdown) {
if (result.markdown !== undefined) {
const parsedBody = await parseMarkdown(result.markdown);
// Recursively process
return expandCodeWidgets(
-4
View File
@@ -29,7 +29,3 @@ functions:
path: "./preview.ts:previewClickHandler"
events:
- preview:click
markdownWidget:
path: ./widget.ts:markdownWidget
codeWidget: markdown
-20
View File
@@ -1,20 +0,0 @@
import { markdown } from "$sb/syscalls.ts";
import type { WidgetContent } from "$sb/app_event.ts";
import { renderMarkdownToHtml } from "./markdown_render.ts";
export async function markdownWidget(
bodyText: string,
): Promise<WidgetContent> {
const mdTree = await markdown.parseMarkdown(bodyText);
const html = renderMarkdownToHtml(mdTree, {
smartHardBreak: true,
});
return Promise.resolve({
html: html,
script: `
document.addEventListener("click", () => {
api({type: "blur"});
});`,
});
}