Plugs: Add command
This commit is contained in:
parent
7f7be814fc
commit
5d89e15959
@ -43,7 +43,10 @@ export async function readYamlPage(
|
|||||||
export async function writeYamlPage(
|
export async function writeYamlPage(
|
||||||
pageName: string,
|
pageName: string,
|
||||||
data: any,
|
data: any,
|
||||||
|
prelude = "",
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const text = YAML.stringify(data);
|
const text = YAML.stringify(data, {
|
||||||
await space.writePage(pageName, "```yaml\n" + text + "\n```");
|
noCompatMode: true,
|
||||||
|
});
|
||||||
|
await space.writePage(pageName, prelude + "```yaml\n" + text + "\n```");
|
||||||
}
|
}
|
||||||
|
@ -333,6 +333,11 @@ functions:
|
|||||||
path: "./plugmanager.ts:getPlugGithubRelease"
|
path: "./plugmanager.ts:getPlugGithubRelease"
|
||||||
events:
|
events:
|
||||||
- get-plug:ghr
|
- get-plug:ghr
|
||||||
|
addPlugCommand:
|
||||||
|
path: ./plugmanager.ts:addPlugCommand
|
||||||
|
command:
|
||||||
|
name: "Plugs: Add"
|
||||||
|
|
||||||
# Debug commands
|
# Debug commands
|
||||||
parseCommand:
|
parseCommand:
|
||||||
path: ./debug.ts:parsePageCommand
|
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 { editor, space, system } from "$sb/silverbullet-syscall/mod.ts";
|
||||||
|
|
||||||
import { readYamlPage } from "$sb/lib/yaml_page.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() {
|
export async function updatePlugsCommand() {
|
||||||
await editor.save();
|
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() {
|
export async function updatePlugs() {
|
||||||
let plugList: string[] = [];
|
let plugList: string[] = [];
|
||||||
try {
|
try {
|
||||||
|
@ -3,6 +3,10 @@ release.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 0.2.1
|
||||||
|
|
||||||
|
* New `Plugs: Add` command
|
||||||
|
|
||||||
## 0.2.0
|
## 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.
|
* 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.
|
* 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
Block a user