Plugs: Add command
parent
7f7be814fc
commit
5d89e15959
|
@ -43,7 +43,10 @@ export async function readYamlPage(
|
|||
export async function writeYamlPage(
|
||||
pageName: string,
|
||||
data: any,
|
||||
prelude = "",
|
||||
): Promise<void> {
|
||||
const text = YAML.stringify(data);
|
||||
await space.writePage(pageName, "```yaml\n" + text + "\n```");
|
||||
const text = YAML.stringify(data, {
|
||||
noCompatMode: true,
|
||||
});
|
||||
await space.writePage(pageName, prelude + "```yaml\n" + text + "\n```");
|
||||
}
|
||||
|
|
|
@ -333,6 +333,11 @@ functions:
|
|||
path: "./plugmanager.ts:getPlugGithubRelease"
|
||||
events:
|
||||
- get-plug:ghr
|
||||
addPlugCommand:
|
||||
path: ./plugmanager.ts:addPlugCommand
|
||||
command:
|
||||
name: "Plugs: Add"
|
||||
|
||||
# Debug commands
|
||||
parseCommand:
|
||||
path: ./debug.ts:parsePageCommand
|
||||
|
|
|
@ -3,6 +3,10 @@ import type { Manifest } from "../../common/manifest.ts";
|
|||
import { editor, space, system } from "$sb/silverbullet-syscall/mod.ts";
|
||||
|
||||
import { readYamlPage } from "$sb/lib/yaml_page.ts";
|
||||
import { writePage } from "$sb/silverbullet-syscall/space.ts";
|
||||
|
||||
const plugsPrelude =
|
||||
"This file lists all plugs that SilverBullet will load. Run the {[Plugs: Update]} command to update and reload this list of plugs.\n\n";
|
||||
|
||||
export async function updatePlugsCommand() {
|
||||
await editor.save();
|
||||
|
@ -16,6 +20,37 @@ export async function updatePlugsCommand() {
|
|||
}
|
||||
}
|
||||
|
||||
export async function addPlugCommand() {
|
||||
let name = await editor.prompt("Plug URI:");
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
// Support people copy & pasting the YAML version
|
||||
if (name.startsWith("-")) {
|
||||
name = name.replace(/^\-\s*/, "");
|
||||
}
|
||||
let plugList: string[] = [];
|
||||
try {
|
||||
plugList = await readYamlPage("PLUGS");
|
||||
} catch (e: any) {
|
||||
console.error("ERROR", e);
|
||||
}
|
||||
if (plugList.includes(name)) {
|
||||
await editor.flashNotification("Plug already installed", "error");
|
||||
return;
|
||||
}
|
||||
plugList.push(name);
|
||||
// await writeYamlPage("PLUGS", plugList, plugsPrelude);
|
||||
await writePage(
|
||||
"PLUGS",
|
||||
plugsPrelude + "```yaml\n" + plugList.map((p) => `- ${p}`).join("\n") +
|
||||
"\n```",
|
||||
);
|
||||
await editor.navigate("PLUGS");
|
||||
await system.invokeFunction("server", "updatePlugs");
|
||||
await editor.flashNotification("Plug added!");
|
||||
}
|
||||
|
||||
export async function updatePlugs() {
|
||||
let plugList: string[] = [];
|
||||
try {
|
||||
|
|
|
@ -3,6 +3,10 @@ release.
|
|||
|
||||
---
|
||||
|
||||
## 0.2.1
|
||||
|
||||
* New `Plugs: Add` command
|
||||
|
||||
## 0.2.0
|
||||
* The editor is now in "live preview" mode where a lot of markdown is hidden unless the cursor is present. This will take some getting used to, but results in a much more distraction free look.
|
||||
* Clicking on the page name in the top bar now allows you to quickly rename pages, hit enter to apply the change.
|
||||
|
|
Loading…
Reference in New Issue