Fixes #8: SETTINGS page to keep all settings
This commit is contained in:
@@ -12,11 +12,8 @@ import { set as storeSet } from "@plugos/plugos-syscall/store";
|
||||
import {
|
||||
flashNotification,
|
||||
getCurrentPage,
|
||||
getCursor,
|
||||
getText,
|
||||
insertAtCursor,
|
||||
matchBefore,
|
||||
moveCursor,
|
||||
navigate,
|
||||
prompt,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
import { dispatch } from "@plugos/plugos-syscall/event";
|
||||
import { Manifest } from "@silverbulletmd/common/manifest";
|
||||
import { findNodeOfType } from "@silverbulletmd/common/tree";
|
||||
import {
|
||||
flashNotification,
|
||||
save,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
|
||||
import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markdown";
|
||||
import {
|
||||
deletePage,
|
||||
listPages,
|
||||
readPage,
|
||||
writePage,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/space";
|
||||
import {
|
||||
invokeFunction,
|
||||
reloadPlugs,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/system";
|
||||
import YAML from "yaml";
|
||||
|
||||
import { readYamlPage } from "../lib/yaml_page";
|
||||
|
||||
async function listPlugs(): Promise<string[]> {
|
||||
let unfilteredPages = await listPages(true);
|
||||
@@ -28,23 +26,22 @@ async function listPlugs(): Promise<string[]> {
|
||||
export async function updatePlugsCommand() {
|
||||
await save();
|
||||
flashNotification("Updating plugs...");
|
||||
await invokeFunction("server", "updatePlugs");
|
||||
flashNotification("And... done!");
|
||||
await reloadPlugs();
|
||||
try {
|
||||
await invokeFunction("server", "updatePlugs");
|
||||
flashNotification("And... done!");
|
||||
await reloadPlugs();
|
||||
} catch (e: any) {
|
||||
flashNotification("Error updating plugs: " + e.message, "error");
|
||||
}
|
||||
}
|
||||
|
||||
export async function updatePlugs() {
|
||||
let { text: plugPageText } = await readPage("PLUGS");
|
||||
|
||||
let tree = await parseMarkdown(plugPageText);
|
||||
|
||||
let codeTextNode = findNodeOfType(tree, "CodeText");
|
||||
if (!codeTextNode) {
|
||||
console.error("Could not find yaml block in PLUGS");
|
||||
return;
|
||||
let plugList: string[] = [];
|
||||
try {
|
||||
plugList = await readYamlPage("PLUGS");
|
||||
} catch (e: any) {
|
||||
throw new Error(`Error processing PLUGS: ${e.message}`);
|
||||
}
|
||||
let plugYaml = codeTextNode.children![0].text;
|
||||
let plugList = YAML.parse(plugYaml!);
|
||||
console.log("Plug YAML", plugList);
|
||||
let allPlugNames: string[] = [];
|
||||
for (let plugUri of plugList) {
|
||||
|
||||
@@ -16,12 +16,14 @@ import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markd
|
||||
import { extractMeta } from "../query/data";
|
||||
import { renderToText } from "@silverbulletmd/common/tree";
|
||||
import { niceDate } from "./dates";
|
||||
|
||||
const pageTemplatePrefix = `template/page/`;
|
||||
const snippetPrefix = `snippet/`;
|
||||
import { readSettings } from "../lib/settings_page";
|
||||
|
||||
export async function instantiateTemplateCommand() {
|
||||
let allPages = await listPages();
|
||||
let { pageTemplatePrefix } = await readSettings({
|
||||
pageTemplatePrefix: "template/page/",
|
||||
});
|
||||
|
||||
let allPageTemplates = allPages.filter((pageMeta) =>
|
||||
pageMeta.name.startsWith(pageTemplatePrefix)
|
||||
);
|
||||
@@ -54,11 +56,17 @@ export async function instantiateTemplateCommand() {
|
||||
|
||||
export async function insertSnippet() {
|
||||
let allPages = await listPages();
|
||||
let { snippetPrefix } = await readSettings({
|
||||
snippetPrefix: "snippet/",
|
||||
});
|
||||
let cursorPos = await getCursor();
|
||||
let page = await getCurrentPage();
|
||||
let allSnippets = allPages.filter((pageMeta) =>
|
||||
pageMeta.name.startsWith(snippetPrefix)
|
||||
);
|
||||
let allSnippets = allPages
|
||||
.filter((pageMeta) => pageMeta.name.startsWith(snippetPrefix))
|
||||
.map((pageMeta) => ({
|
||||
...pageMeta,
|
||||
name: pageMeta.name.slice(snippetPrefix.length),
|
||||
}));
|
||||
|
||||
let selectedSnippet = await filterBox(
|
||||
"Snippet",
|
||||
@@ -69,7 +77,7 @@ export async function insertSnippet() {
|
||||
if (!selectedSnippet) {
|
||||
return;
|
||||
}
|
||||
let { text } = await readPage(selectedSnippet.name);
|
||||
let { text } = await readPage(`${snippetPrefix}${selectedSnippet.name}`);
|
||||
|
||||
let templateText = replaceTemplateVars(text, page);
|
||||
let carretPos = templateText.indexOf("|^|");
|
||||
|
||||
Reference in New Issue
Block a user