Implementation of #117: sharing

This commit is contained in:
Zef Hemel
2022-11-24 16:08:51 +01:00
parent 5b1ec14891
commit b61e8ff681
12 changed files with 78 additions and 25 deletions
+9 -9
View File
@@ -1,26 +1,26 @@
import { events } from "$sb/plugos-syscall/mod.ts";
import { editor, markdown, system } from "$sb/silverbullet-syscall/mod.ts";
import { extractFrontmatter } from "$sb/lib/frontmatter.ts";
export type PublishEvent = {
uri: string;
// Page name
name: string;
};
import { PublishEvent } from "$sb/app_event.ts";
export async function publishCommand() {
await editor.save();
const text = await editor.getText();
const pageName = await editor.getCurrentPage();
const tree = await markdown.parseMarkdown(text);
let { $share } = extractFrontmatter(tree);
const { $share } = extractFrontmatter(tree);
if (!$share) {
await editor.flashNotification("No $share directive found", "error");
await editor.flashNotification("Saved.");
return;
}
if (!Array.isArray($share)) {
$share = [$share];
await editor.flashNotification(
"$share front matter must be an array.",
"error",
);
return;
}
await editor.flashNotification("Sharing...");
// Delegate actual publishing to the server
try {
await system.invokeFunction("server", "publish", pageName, $share);
+2
View File
@@ -4,6 +4,8 @@ functions:
path: publish.ts:publishCommand
command:
name: "Share: Publish"
key: "Ctrl-s"
mac: "Cmd-s"
publish:
path: publish.ts:publish
env: server