1
0

Change all SETTINGS with page references to allow "[[page]]" notation

This commit is contained in:
Zef Hemel 2023-08-17 20:27:05 +02:00
parent 6b3649c345
commit b273645bae
7 changed files with 34 additions and 19 deletions

View File

@ -1,4 +1,5 @@
import {
cleanPageRef,
federatedPathToUrl,
resolvePath,
rewritePageRefs,
@ -38,6 +39,9 @@ Deno.test("Test URL resolver", () => {
federatedPathToUrl("!silverbullet.md/index"),
"https://silverbullet.md/index",
);
assertEquals(cleanPageRef("hello"), "hello");
assertEquals(cleanPageRef("[[hello]]"), "hello");
});
Deno.test("Test rewritePageRefs", () => {

View File

@ -66,3 +66,11 @@ export function rewritePageRefs(tree: ParseTree, containerPageName: string) {
return false;
});
}
export function cleanPageRef(pageRef: string) {
if (pageRef.startsWith("[[") && pageRef.endsWith("]]")) {
return pageRef.slice(2, -2);
} else {
return pageRef;
}
}

View File

@ -7,6 +7,7 @@ import { PageMeta } from "../../web/types.ts";
import { buildHandebarOptions } from "../directive/util.ts";
import Handlebars from "handlebars";
import { cleanPageRef } from "$sb/lib/resolve.ts";
export async function instantiateTemplateCommand() {
const allPages = await space.listPages();
@ -176,7 +177,7 @@ export async function quickNoteCommand() {
export async function dailyNoteCommand() {
const { dailyNoteTemplate, dailyNotePrefix } = await readSettings({
dailyNoteTemplate: "template/page/Daily Note",
dailyNoteTemplate: "[[template/page/Daily Note]]",
dailyNotePrefix: "📅 ",
});
const date = niceDate(new Date());
@ -189,7 +190,9 @@ export async function dailyNoteCommand() {
// Doesn't exist, let's create
let dailyNoteTemplateText = "";
try {
dailyNoteTemplateText = await space.readPage(dailyNoteTemplate);
dailyNoteTemplateText = await space.readPage(
cleanPageRef(dailyNoteTemplate),
);
carretPos = dailyNoteTemplateText.indexOf("|^|");
if (carretPos === -1) {
carretPos = 0;
@ -224,13 +227,15 @@ function getWeekStartDate(monday = false) {
export async function weeklyNoteCommand() {
const { weeklyNoteTemplate, weeklyNotePrefix, weeklyNoteMonday } =
await readSettings({
weeklyNoteTemplate: "template/page/Weekly Note",
weeklyNoteTemplate: "[[template/page/Weekly Note]]",
weeklyNotePrefix: "🗓️ ",
weeklyNoteMonday: false,
});
let weeklyNoteTemplateText = "";
try {
weeklyNoteTemplateText = await space.readPage(weeklyNoteTemplate);
weeklyNoteTemplateText = await space.readPage(
cleanPageRef(weeklyNoteTemplate),
);
} catch {
console.warn(`No weekly note template found at ${weeklyNoteTemplate}`);
}

View File

@ -34,6 +34,7 @@ import { createEditorState } from "./editor_state.ts";
import { OpenPages } from "./open_pages.ts";
import { MainUI } from "./editor_ui.tsx";
import { DexieMQ } from "../plugos/lib/mq.dexie.ts";
import { cleanPageRef } from "$sb/lib/resolve.ts";
const frontMatterRegex = /^---\n(([^\n]|\n)*?)---\n/;
const autoSaveInterval = 1000;
@ -250,7 +251,7 @@ export class Client {
private initNavigator() {
this.pageNavigator = new PathPageNavigator(
this.settings.indexPage,
cleanPageRef(this.settings.indexPage),
);
this.pageNavigator.subscribe(async (pageName, pos: number | string) => {
@ -386,12 +387,12 @@ export class Client {
settingsText = (await this.space.readPage("SETTINGS")).text;
} catch (e) {
console.info("No SETTINGS page, falling back to default", e);
settingsText = "```yaml\nindexPage: index\n```\n";
settingsText = '```yaml\nindexPage: "[[index]]"\n```\n';
}
const settings = parseYamlSettings(settingsText!) as BuiltinSettings;
if (!settings.indexPage) {
settings.indexPage = "index";
settings.indexPage = "[[index]]";
}
return settings;
}
@ -667,7 +668,7 @@ export class Client {
newWindow = false,
) {
if (!name) {
name = this.settings!.indexPage;
name = cleanPageRef(this.settings.indexPage);
}
try {
@ -772,7 +773,7 @@ export class Client {
if (this.settings.customStyles) {
try {
const { text: stylesText } = await this.space.readPage(
this.settings?.customStyles,
cleanPageRef(this.settings.customStyles),
);
const cssBlockRegex = /```css([^`]+)```/;
const match = cssBlockRegex.exec(stylesText);

View File

@ -1,6 +0,0 @@
```yaml
title: SilverBullet
publishAll: true
indexPage: SilverBullet
footerPage: website-footer
```

View File

@ -2,10 +2,10 @@ This page contains settings for configuring SilverBullet and its Plugs. Changing
```yaml
# Initial page to load when launching SB
indexPage: SilverBullet
indexPage: "[[SilverBullet]]"
# Load custom CSS styles from the following page
customStyles: STYLES
customStyles: "[[STYLES]]"
# Template related settings
pageTemplatePrefix: "template/page/"
@ -14,10 +14,10 @@ snippetPrefix: "snippet/"
quickNotePrefix: "📥 "
dailyNotePrefix: "📅 "
dailyNoteTemplate: "template/page/Daily Note"
dailyNoteTemplate: "[[template/page/Daily Note]]"
weeklyNotePrefix: "🗓️ "
weeklyNoteTemplate: "template/page/Weekly Note"
weeklyNoteTemplate: "[[template/page/Weekly Note]]"
weeklyNoteMonday: false
# Markdown

View File

@ -0,0 +1,3 @@
This is my weekly note template.
|^|