SilverBullet pivot to become an offline-first PWA (#403)

This commit is contained in:
Zef Hemel
2023-05-23 20:53:53 +02:00
committed by GitHub
parent b256269897
commit 5f484bed57
389 changed files with 4484 additions and 291129 deletions
+9 -19
View File
@@ -1,6 +1,5 @@
import { editor, markdown, system } from "$sb/silverbullet-syscall/mod.ts";
import { editor, markdown, sync } from "$sb/silverbullet-syscall/mod.ts";
import {
ParseTree,
removeParentPointers,
renderToText,
traverseTree,
@@ -14,12 +13,17 @@ export async function updateDirectivesOnPageCommand(arg: any) {
const pageName = await editor.getCurrentPage();
const text = await editor.getText();
const tree = await markdown.parseMarkdown(text);
const metaData = extractFrontmatter(tree, ["$disableDirectives"]);
const metaData = await extractFrontmatter(tree, ["$disableDirectives"]);
if (metaData.$disableDirectives) {
// Not updating, directives disabled
return;
}
// if (!(await sync.hasInitialSyncCompleted())) {
// console.info("Initial sync hasn't completed yet, not updating directives.");
// return;
// }
// If this page is shared ($share) via collab: disable directives as well
// due to security concerns
if (metaData.$share) {
@@ -51,12 +55,7 @@ export async function updateDirectivesOnPageCommand(arg: any) {
}
const fullMatch = text.substring(tree.from!, tree.to!);
try {
const promise = system.invokeFunction(
"server",
"serverRenderDirective",
pageName,
tree,
);
const promise = renderDirectives(pageName, tree);
replacements.push({
textPromise: promise,
fullMatch,
@@ -116,17 +115,8 @@ export async function updateDirectivesOnPageCommand(arg: any) {
}
}
// Called from client, running on server
// The text passed here is going to be a single directive block (not a full page)
export function serverRenderDirective(
pageName: string,
tree: ParseTree,
): Promise<string> {
return renderDirectives(pageName, tree);
}
// Pure server driven implementation of directive updating
export async function serverUpdateDirectives(
export async function updateDirectives(
pageName: string,
text: string,
) {