From 4133cabd527c0ece0994fb64fb8fde48ec65b537 Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Sat, 20 Jan 2024 22:53:51 +0100 Subject: [PATCH] Fixing netlify --- common/PAGE_TEMPLATES.ts | 6 +++-- common/spaces/http_space_primitives.ts | 5 ++++ common/util.ts | 3 +-- netlify/edge-functions/handle.ts | 16 +++++++++++++ plugs/federation/library.ts | 2 ++ scripts/build_website.sh | 1 - web/cm_plugins/markdown_widget.ts | 5 ++++ web/hooks/command.ts | 2 +- web/styles/editor.scss | 4 ++++ website/Getting Started.md | 32 ++++++++++++++++++-------- website/_redirects | 1 - 11 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 netlify/edge-functions/handle.ts diff --git a/common/PAGE_TEMPLATES.ts b/common/PAGE_TEMPLATES.ts index 53a3b20..29b1f5b 100644 --- a/common/PAGE_TEMPLATES.ts +++ b/common/PAGE_TEMPLATES.ts @@ -8,9 +8,11 @@ indexPage: index `; export const INDEX_TEMPLATE = - `Hello! And welcome to your brand new SilverBullet space! + `This is the index page of your fresh SilverBullet space. It is the default page that is loaded when you open a space. + +For your convenience we're including an on-boarding live template below. Enjoy! \`\`\`template -page: "[[!silverbullet.md/Getting Started]]" +page: "[[!localhost:3001/Getting Started]]" \`\`\` `; diff --git a/common/spaces/http_space_primitives.ts b/common/spaces/http_space_primitives.ts index 8ca2574..9c3cc5f 100644 --- a/common/spaces/http_space_primitives.ts +++ b/common/spaces/http_space_primitives.ts @@ -57,6 +57,11 @@ export class HttpSpacePrimitives implements SpacePrimitives { if ( errorMessage.includes("fetch") || errorMessage.includes("load failed") ) { + console.error( + "Got error fetching, throwing offline", + url, + e.errorMessage, + ); throw new Error("Offline"); } throw e; diff --git a/common/util.ts b/common/util.ts index 17f48d7..e199527 100644 --- a/common/util.ts +++ b/common/util.ts @@ -1,9 +1,8 @@ -import { SETTINGS_TEMPLATE } from "./PAGE_TEMPLATES.ts"; +import { INDEX_TEMPLATE, SETTINGS_TEMPLATE } from "./PAGE_TEMPLATES.ts"; import { YAML } from "./deps.ts"; import { SpacePrimitives } from "./spaces/space_primitives.ts"; import { expandPropertyNames } from "$sb/lib/json.ts"; import type { BuiltinSettings } from "../web/types.ts"; -import { INDEX_TEMPLATE } from "./PAGE_TEMPLATES.ts"; /** * Runs a function safely by catching any errors and logging them to the console. diff --git a/netlify/edge-functions/handle.ts b/netlify/edge-functions/handle.ts new file mode 100644 index 0000000..ec61938 --- /dev/null +++ b/netlify/edge-functions/handle.ts @@ -0,0 +1,16 @@ +export default async function handleMarkdown( + request: Request, + ctx: any, +): Promise { + const resp = await ctx.next(request); + if (resp.status === 404) { + return new Response("", { + status: 200, + headers: { "Content-Type": "text/markdown" }, + }); + } else { + return resp; + } +} + +export const config = { path: "/*.md" }; diff --git a/plugs/federation/library.ts b/plugs/federation/library.ts index e97b6d5..b744765 100644 --- a/plugs/federation/library.ts +++ b/plugs/federation/library.ts @@ -49,6 +49,8 @@ export async function importLibraryCommand(_def: any, uri?: string) { // Write to local space await space.writePage(pageName, new TextDecoder().decode(buf)); + + await editor.flashNotification(`Imported ${pageName}`); } await editor.reloadSettingsAndCommands(); await editor.flashNotification("Import complete!"); diff --git a/scripts/build_website.sh b/scripts/build_website.sh index 4e425e7..3c082a3 100755 --- a/scripts/build_website.sh +++ b/scripts/build_website.sh @@ -39,7 +39,6 @@ cat website/_headers | sed "s/12345/$LAST_MODIFIED_TIMESTAMP/g" > website_build/ echo "Generating file listing" deno run -A scripts/generate_fs_list.ts > website_build/index.json -echo > website_build/empty.md #echo "Bundling..." deno task bundle diff --git a/web/cm_plugins/markdown_widget.ts b/web/cm_plugins/markdown_widget.ts index 1e225a9..512f543 100644 --- a/web/cm_plugins/markdown_widget.ts +++ b/web/cm_plugins/markdown_widget.ts @@ -136,6 +136,11 @@ export class MarkdownWidget extends WidgetType { } private attachListeners(div: HTMLElement, buttons?: CodeWidgetButton[]) { + div.addEventListener("mousedown", (e) => { + // CodeMirror overrides mousedown on parent elements to implement its own selection highlighting. + // That's nice, but not for markdown widgets, so let's not propagate the event to CodeMirror here. + e.stopPropagation(); + }); // Override wiki links with local navigate (faster) div.querySelectorAll("a[data-ref]").forEach((el_) => { const el = el_ as HTMLElement; diff --git a/web/hooks/command.ts b/web/hooks/command.ts index 1688a72..4ede9bf 100644 --- a/web/hooks/command.ts +++ b/web/hooks/command.ts @@ -42,7 +42,7 @@ export class CommandHook extends EventEmitter throttledBuildAllCommands = throttle(() => { this.buildAllCommands().catch(console.error); - }, 1000); + }, 200); async buildAllCommands() { this.editorCommands.clear(); diff --git a/web/styles/editor.scss b/web/styles/editor.scss index de21c7b..bc33652 100644 --- a/web/styles/editor.scss +++ b/web/styles/editor.scss @@ -410,6 +410,10 @@ .sb-markdown-widget { margin: 0 0 -4ch 0; + + ::selection { + background-color: var(--editor-selection-background-color) !important; + } } .sb-markdown-top-widget h1, diff --git a/website/Getting Started.md b/website/Getting Started.md index 8b5c379..45cdd70 100644 --- a/website/Getting Started.md +++ b/website/Getting Started.md @@ -1,21 +1,27 @@ -Welcome to SilverBullet. Since you’re starting fresh, you may want to kick off by importing the [[Library/Core]] [[Libraries|library]] of templates and pages. You can do so easily with the button below. Just push it — you know you want to! +# Hello there! +Welcome to the wondrous world of SilverBullet. A world that once you discover and appreciate, you’ll never want to leave. -{[Library: Import|Import Core Library]("!silverbullet.md/Library/Core/")} +_One of us!_ -Did that? Let’s proceed. +Out of the box SilverBullet is fairly minimal in terms of functionality. To give you a good “first run” experience, we recommend you start by importing the [[Library/Core]] library into your space. This will give you a couple of useful pages, slash commands, page templates and widgets such as [[Table of Contents]] and [[Linked Mentions]] to start of with. If you have no idea what those are — don’t worry about it. Just keep going, you’ll get the hang of things. -## Getting started -The best way to get a good feel for what SilverBullet is to immediately start playing with it. Here are some things for you to try: +Just push this button: {[Library: Import|Import Core Library]("!silverbullet.md/Library/Core/")} + +You know you want to. + +Just do it. + +# Next steps +Now that you have some basics stuff in place, it’s time to start playing a bit. * 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. - * You _can_ create pages in folders (if you’re into that type of thing) simply by putting slashes (`/`) in the name (even on Windows), e.g. `My Folder/My Page`. Don’t worry about that folder existing, we’ll automatically create it if it doesn’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]]. The {[Stats: Show]} one is a safe one to try. + * 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, we’ll 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]]. The {[Stats: Show]} one is a safe one to try. * Click on the “T” icon (top right), or hit `Cmd-Shift-t` (Mac) or `Ctrl-Shift-t` (Linux and Windows) to open the [[Template Picker]] and see what templates you have installed (which should be a few after importing the Core library) * Select some text and hit `Alt-m` to ==highlight== it, or `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_. * Click a link somewhere on this page to navigate there. When you link to a new page it will initially show up in red (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 `[[` somewhere to insert your own page link (with completion). -* [ ] Tap this box 👈 to mark this task as done. * 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, you can click this button {[Editor: Toggle Vim Mode]} to toggle Vim mode. If you cannot figure out how to exit it, just click that button again. _Phew!_ @@ -35,11 +41,17 @@ page select name order by name limit 10 ``` ## What next? -If you are a visual learner, you may [enjoy this introduction video on Youtube](https://youtu.be/VemS-cqAD5k). +If you are a visual learner, you may [enjoy this introduction video on Youtube](https://www.youtube.com/watch?v=BbNbZgOwB-Y). Beyond that, you can find more information about SilverBullet on its official website. You have two ways to access it: 1. Through its [regular website link](https://silverbullet.md/) 2. Directly without leaving SilverBullet, through [[Federation]], just click on this: [[SilverBullet]] (note that all of these will be read-only, for obvious reasons) -To keep up with the latest and greatest going-ons in SilverBullet land, keep an eye on the [[CHANGELOG]]. \ No newline at end of file +To keep up with the latest and greatest goings-on in SilverBullet land, keep an eye on the [[CHANGELOG]]. + +Got any more questions? Join our [community](https://community.silverbullet.md/). + +Feel a bit more ready in this endeavor? If so, feel to remove the [[Live Templates|live template]] that renders this on-boarding description. You’re on your own now. + +You got this. \ No newline at end of file diff --git a/website/_redirects b/website/_redirects index f39e12c..95afc94 100644 --- a/website/_redirects +++ b/website/_redirects @@ -1,3 +1,2 @@ -# /.fs /index.json 200 /.client/* /_client/:splat 200! /* /_client/index.html 200 \ No newline at end of file