Bringing in config and config docs
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
#meta
|
||||
|
||||
This defines the [JSON schema](https://json-schema.org/) for built-in settings.
|
||||
|
||||
```space-lua
|
||||
config.define("autoCloseBrackets", {
|
||||
description = "List of brackets to auto close",
|
||||
type = "string",
|
||||
})
|
||||
|
||||
config.define("emoji", {
|
||||
description = "Additional emoji aliases",
|
||||
type = "object",
|
||||
properties = {
|
||||
aliases = {
|
||||
type = "object",
|
||||
additionalProperties = { type = "string" }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
config.define("shortcuts", {
|
||||
type = "array",
|
||||
items = {
|
||||
type = "object",
|
||||
properties = {
|
||||
command = {
|
||||
type = "string",
|
||||
description = "Command we're creating the shortcut for"
|
||||
},
|
||||
key = {
|
||||
type = "string",
|
||||
description = "(Re)bind to keyboard shortcut"
|
||||
},
|
||||
mac = {
|
||||
type = "string",
|
||||
description = "Mac-specific keyboard shortcut"
|
||||
},
|
||||
slashCommand = {
|
||||
type = "string",
|
||||
description = "Bind to slash command"
|
||||
},
|
||||
priority = {
|
||||
type = "number",
|
||||
description = "Tweak priority in command palette"
|
||||
}
|
||||
},
|
||||
required = {"command"},
|
||||
additionalProperties = false
|
||||
}
|
||||
})
|
||||
|
||||
config.define("smartQuotes", {
|
||||
description = "Configure smart quotes",
|
||||
type = "object",
|
||||
properties = {
|
||||
enabled = {
|
||||
type = "boolean",
|
||||
description = "Indicates whether smart quotes are enabled"
|
||||
},
|
||||
double = {
|
||||
type = "object",
|
||||
properties = {
|
||||
left = {
|
||||
type = "string",
|
||||
description = "Character for the left double quote"
|
||||
},
|
||||
right = {
|
||||
type = "string",
|
||||
description = "Character for the right double quote"
|
||||
}
|
||||
},
|
||||
additionalProperties = false
|
||||
},
|
||||
single = {
|
||||
type = "object",
|
||||
properties = {
|
||||
left = {
|
||||
type = "string",
|
||||
description = "Character for the left single quote"
|
||||
},
|
||||
right = {
|
||||
type = "string",
|
||||
description = "Character for the right single quote"
|
||||
}
|
||||
},
|
||||
additionalProperties = false
|
||||
},
|
||||
},
|
||||
additionalProperties = false
|
||||
})
|
||||
|
||||
config.define("mobileMenuStyle", {
|
||||
type = "string",
|
||||
})
|
||||
|
||||
config.define("actionButtons", {
|
||||
type = "array",
|
||||
items = {
|
||||
type = "object",
|
||||
properties = {
|
||||
icon = {
|
||||
type = "string",
|
||||
description = "Icon representing the action button"
|
||||
},
|
||||
description = {
|
||||
type = "string",
|
||||
description = "Optional description of the action button"
|
||||
},
|
||||
command = {
|
||||
type = "string",
|
||||
description = "Command the action button executes"
|
||||
},
|
||||
args = {
|
||||
type = "array",
|
||||
description = "Optional array of arguments for the command"
|
||||
},
|
||||
mobile = {
|
||||
type = "boolean",
|
||||
description = "Optional boolean indicating if the action button is applicable for mobile"
|
||||
}
|
||||
},
|
||||
required = {"icon", "command"},
|
||||
additionalProperties = false
|
||||
}
|
||||
})
|
||||
|
||||
```
|
||||
@@ -1,3 +1,5 @@
|
||||
#meta
|
||||
|
||||
# Quick Note
|
||||
```space-lua
|
||||
command.define {
|
||||
|
||||
+53
-14
@@ -1,19 +1,58 @@
|
||||
export const SETTINGS_TEMPLATE = `#meta
|
||||
export const INDEX_TEMPLATE = `# Hello 👋
|
||||
Welcome to the wondrous world of SilverBullet. A world that once you discover and appreciate, you’ll never want to leave.
|
||||
|
||||
This page contains some configuration overrides for SilverBullet. A list of configs and their documentation [[!silverbullet.md/SETTINGS|can be found here]].
|
||||
_One of us!_
|
||||
|
||||
To update the [[!silverbullet.md/Libraries|libraries]] specified below, run {[Libraries: Update]}
|
||||
You can go ahead delete this placeholder content in a second, but before you do, let me quickly show you around.
|
||||
|
||||
\`\`\`yaml
|
||||
libraries:
|
||||
- import: "[[!silverbullet.md/Library/Core/*]]"
|
||||
We’ll do this through a list of **silver bullets**. _Ah, so that explains the name!_ Well, [partially](https://en.wikipedia.org/wiki/Silver_bullet).
|
||||
|
||||
* Click on the page picker (book icon) icon at the top right, or hit \`Cmd-k\` (Mac) or \`Ctrl-k\` (Linux and Windows) to open the **page picker**.
|
||||
* Type the name of a non-existent page to create it.
|
||||
* Folders are implicitly created by putting slashes (\`/\`) in the name (even on Windows), e.g. \`My Folder/My Page\`. Don’t worry about folders existing, SilverBullet will automatically create them if they don’t.
|
||||
* Click on the terminal icon (top right), or hit \`Cmd-/\` (Mac) or \`Ctrl-/\` (Linux and Windows), or tap the screen with 3 fingers at the same time (on mobile) to open the **command palette**. From here you can run various useful and perhaps less useful commands.
|
||||
* Select some text and hit \`Cmd-b\` (Mac) or \`Ctrl-b\` (Windows/Linux) to make it **bold**, or \`Cmd-i\` (Mac) or \`Ctrl-i\` (Windows/Linux) to make it _italic_.
|
||||
* You can create links to pages using the \`[[other page]]\` syntax, for instance: [[aspiring page]]. When you link to a non-existent page it will initially show up in orange (to indicate it does not yet exist), but once you click it — you will create the page automatically (only for real when you actually enter some text).
|
||||
* Start typing \`:party\` to trigger the emoji picker 🎉
|
||||
* Type \`/\` somewhere in the text to invoke a **slash command**.
|
||||
* If this is matching your personality type, there is also a \`Editor: Toggle Vim Mode\` command to switch to Vim mode. If you cannot figure out how to exit it (classic vim issue), just run that same command again. _Phew!_
|
||||
* As you may have noticed, while SilverBullet uses [markdown](https://www.markdownguide.org/) underneath, it also “live previews” it to give a bit more of a WYSIWYG feel. You can always move your cursor “into” the underlying code by \`Alt-clicking\` it (even links and widgets, which we’ll get to later).
|
||||
|
||||
While SilverBullet implements (most) of [CommonMark](https://commonmark.org/), it also adds a few extensions that are SilverBullet specific. Most notably, it adds the \`\${Lua expression}\` syntax, to render Lua expression inline.
|
||||
|
||||
Using SilverBullet’s Lua APIs, you can do all kinds of cool stuff. For instance, query your space for the last 3 modified pages. _Exciting!_
|
||||
|
||||
\${query[[from index.tag "page" order by lastModified limit 3]]}
|
||||
|
||||
There’s a whole world out there to explore, but let’s not get ahead of ourselves. First, have some fun and add some content to your fresh space.
|
||||
|
||||
Then we’ll talk.
|
||||
|
||||
# What next?
|
||||
You find more information on SilverBullet’s feature set on its [official website](https://v2.silverbullet.md/). Also be sure to join the [SilverBullet community](https://community.silverbullet.md/) to interact with fellow SilverBullet explorers.`;
|
||||
|
||||
export const CONFIG_TEMPLATE = `# SilverBullet Configuration
|
||||
This is where you configure SilverBullet to your liking. See [[^Library/Std/Config]] for a full list of configuration options.
|
||||
|
||||
\`\`\`space-lua
|
||||
config.set {
|
||||
actionButtons = {
|
||||
{
|
||||
icon = "home",
|
||||
command = "Navigate: Home",
|
||||
description = "Go to the index page"
|
||||
},
|
||||
{
|
||||
icon = "book",
|
||||
command = "Navigate: Page Picker",
|
||||
description = "Open page"
|
||||
},
|
||||
{
|
||||
icon = "terminal",
|
||||
command = "Open Command Palette",
|
||||
description = "Run command"
|
||||
}
|
||||
},
|
||||
}
|
||||
\`\`\`
|
||||
`;
|
||||
|
||||
export const INDEX_TEMPLATE =
|
||||
`This is the index page of your fresh SilverBullet space. It is the default page that is loaded when you open a space. In addition, there is also a [[^SETTINGS]] page that contains SilverBullet configuration.
|
||||
|
||||
For your convenience we're embedding some on-boarding info below. Feel free to delete it once you're done reading it.
|
||||
|
||||
![[!silverbullet.md/Getting Started]]
|
||||
`;
|
||||
|
||||
+10
-2
@@ -1,10 +1,10 @@
|
||||
import Ajv from "ajv";
|
||||
|
||||
export class Config {
|
||||
private schemas: Record<string, any> = {};
|
||||
public schemas: Record<string, any> = {};
|
||||
private ajv = new Ajv();
|
||||
|
||||
constructor(private values: Record<string, any> = {}) {
|
||||
constructor(public values: Record<string, any> = {}) {
|
||||
// Add the same formats as in jsonschema.ts
|
||||
this.ajv.addFormat("email", {
|
||||
validate: (data: string) => {
|
||||
@@ -147,4 +147,12 @@ export class Config {
|
||||
|
||||
return resolved.key in resolved.obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all configuration keys in the config
|
||||
* @returns An array of keys
|
||||
*/
|
||||
keys(): string[] {
|
||||
return Object.keys(this.values);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,10 @@ export class DiskSpacePrimitives implements SpacePrimitives {
|
||||
lastModified: s.mtime?.getTime() || 0,
|
||||
perm: "rw",
|
||||
};
|
||||
} catch {
|
||||
} catch (e: any) {
|
||||
if (e instanceof Deno.errors.NotFound) {
|
||||
throw Error("Not found");
|
||||
}
|
||||
// console.error("Error while getting page meta", pageName, e);
|
||||
throw Error(`Could not get meta for ${name}`);
|
||||
}
|
||||
|
||||
@@ -23,5 +23,11 @@ export function configSyscalls(client: Client): SysCallMapping {
|
||||
"config.define": (_ctx, key: string, schema: any) => {
|
||||
client.config.define(key, schema);
|
||||
},
|
||||
"config.getValues": () => {
|
||||
return client.config.values;
|
||||
},
|
||||
"config.getSchemas": () => {
|
||||
return client.config.schemas;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { ShellBackend } from "./shell_backend.ts";
|
||||
import { determineStorageBackend } from "./storage_backend.ts";
|
||||
import type { ServerOptions } from "./http_server.ts";
|
||||
import type { AuthOptions } from "../cmd/server.ts";
|
||||
import { CONFIG_TEMPLATE, INDEX_TEMPLATE } from "$common/PAGE_TEMPLATES.ts";
|
||||
|
||||
// Equivalent of Client on the server
|
||||
export class SpaceServer {
|
||||
@@ -73,6 +74,30 @@ export class SpaceServer {
|
||||
);
|
||||
}
|
||||
|
||||
await this.ensureBasicPages();
|
||||
|
||||
console.log("Booted server with hostname", this.hostname);
|
||||
}
|
||||
|
||||
async ensureBasicPages() {
|
||||
await this.ensurePageWithContent("index.md", INDEX_TEMPLATE);
|
||||
await this.ensurePageWithContent("CONFIG.md", CONFIG_TEMPLATE);
|
||||
}
|
||||
|
||||
private async ensurePageWithContent(path: string, content: string) {
|
||||
try {
|
||||
// This will blow up if the page doesn't exist
|
||||
await this.spacePrimitives.getFileMeta(path);
|
||||
} catch (e: any) {
|
||||
if (e.message === "Not found") {
|
||||
console.info(path, "page not found, creating...");
|
||||
await this.spacePrimitives.writeFile(
|
||||
path,
|
||||
new TextEncoder().encode(content),
|
||||
);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,6 +332,7 @@ export class MainUI {
|
||||
callback: () => {
|
||||
client.runCommandByName(
|
||||
button.command,
|
||||
button.args || [],
|
||||
);
|
||||
},
|
||||
href: "",
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# SilverBullet Configuration
|
||||
```space-lua
|
||||
config.set {
|
||||
actionButtons = {
|
||||
{
|
||||
icon = "home",
|
||||
command = "Navigate: Home",
|
||||
description = "Go to the index page"
|
||||
},
|
||||
{
|
||||
icon = "activity",
|
||||
description = "What's new",
|
||||
command = "Navigate: To Page",
|
||||
args = {"CHANGELOG"}
|
||||
},
|
||||
{
|
||||
icon = "message-circle",
|
||||
description = "Community",
|
||||
command = "Navigate: To URL",
|
||||
args = {"https://community.silverbullet.md"}
|
||||
},
|
||||
{
|
||||
icon = "book",
|
||||
command = "Navigate: Page Picker",
|
||||
description = "Open page"
|
||||
},
|
||||
{
|
||||
icon = "terminal",
|
||||
command = "Open Command Palette",
|
||||
description = "Run command"
|
||||
}
|
||||
},
|
||||
smartQuotes = {
|
||||
enabled = true,
|
||||
},
|
||||
shortcuts = {
|
||||
{
|
||||
command = "Stats: Show",
|
||||
key = "Ctrl-Shift-s",
|
||||
slashCommand = "stats"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
+1
-1
@@ -1 +1 @@
|
||||
Moved to [[SilverBullet]]
|
||||
You want to be here, trust me: [[SilverBullet]]
|
||||
Reference in New Issue
Block a user