@@ -0,0 +1,7 @@
|
||||
export const SETTINGS_TEMPLATE =
|
||||
`This page contains settings for configuring SilverBullet and its plugs. Any changes outside of the yaml block will be overwritten.
|
||||
|
||||
\`\`\`yaml
|
||||
indexPage: index
|
||||
\`\`\`
|
||||
`;
|
||||
@@ -26,7 +26,6 @@ export class Space extends EventEmitter<SpaceEvents> {
|
||||
|
||||
public async updatePageList() {
|
||||
const newPageList = await this.fetchPageList();
|
||||
// console.log("Updating page list", newPageList);
|
||||
const deletedPages = new Set<string>(this.pageMetaCache.keys());
|
||||
newPageList.forEach((meta) => {
|
||||
const pageName = meta.name;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { SETTINGS_TEMPLATE } from "./settings_template.ts";
|
||||
import { YAML } from "./deps.ts";
|
||||
import { Space } from "./spaces/space.ts";
|
||||
|
||||
export function safeRun(fn: () => Promise<void>) {
|
||||
fn().catch((e) => {
|
||||
@@ -42,3 +44,32 @@ export function parseYamlSettings(settingsMarkdown: string): {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export async function ensureAndLoadSettings(space: Space) {
|
||||
try {
|
||||
await space.getPageMeta("SETTINGS");
|
||||
} catch {
|
||||
await space.writePage(
|
||||
"SETTINGS",
|
||||
SETTINGS_TEMPLATE,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
const { text: settingsText } = await space.readPage("SETTINGS");
|
||||
const settings = parseYamlSettings(settingsText);
|
||||
if (!settings.indexPage) {
|
||||
settings.indexPage = "index";
|
||||
}
|
||||
|
||||
try {
|
||||
await space.getPageMeta(settings.indexPage);
|
||||
} catch {
|
||||
await space.writePage(
|
||||
settings.indexPage,
|
||||
`Welcome to your new space!`,
|
||||
);
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user