diff --git a/packages/plugs/core/core.plug.yaml b/packages/plugs/core/core.plug.yaml index dfc8a7b4..cd5e1471 100644 --- a/packages/plugs/core/core.plug.yaml +++ b/packages/plugs/core/core.plug.yaml @@ -184,6 +184,22 @@ functions: + insertInclude: + path: "./template.ts:insertTemplateText" + slashCommand: + name: include + value: | + + + + insertInlineTemplate: + path: "./template.ts:insertTemplateText" + slashCommand: + name: inline-template + value: | + + + quickNoteCommand: path: ./template.ts:quickNoteCommand command: diff --git a/packages/plugs/query/complete.ts b/packages/plugs/query/complete.ts index 47ceb328..40ff172f 100644 --- a/packages/plugs/query/complete.ts +++ b/packages/plugs/query/complete.ts @@ -30,11 +30,22 @@ export async function queryComplete() { }; } - prefix = await matchBefore('#inst "[^"]*'); + prefix = await matchBefore('#template "[^"]*'); if (prefix) { let allPages = await listPages(); return { - from: prefix.from + '#inst "'.length, + from: prefix.from + '#template "'.length, + options: allPages.map((pageMeta) => ({ + label: pageMeta.name, + })), + }; + } + + prefix = await matchBefore('#include "[^"]*'); + if (prefix) { + let allPages = await listPages(); + return { + from: prefix.from + '#include "'.length, options: allPages.map((pageMeta) => ({ label: pageMeta.name, })), diff --git a/packages/plugs/query/materialized_queries.ts b/packages/plugs/query/materialized_queries.ts index 53fdd033..ca13b567 100644 --- a/packages/plugs/query/materialized_queries.ts +++ b/packages/plugs/query/materialized_queries.ts @@ -16,6 +16,8 @@ import { replaceTemplateVars } from "../core/template"; import { jsonToMDTable, queryRegex } from "./util"; import { dispatch } from "@plugos/plugos-syscall/event"; import { replaceAsync } from "../lib/util"; +import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markdown"; +import { nodeAtPos } from "@silverbulletmd/common/tree"; export async function updateMaterializedQueriesCommand() { const currentPage = await getCurrentPage(); @@ -32,7 +34,7 @@ export async function updateMaterializedQueriesCommand() { } export const templateInstRegex = - /()(.+?)()/gs; + /()(.+?)()/gs; async function updateTemplateInstantiations( text: string, @@ -41,7 +43,7 @@ async function updateTemplateInstantiations( return replaceAsync( text, templateInstRegex, - async (fullMatch, startInst, template, args, body, endInst) => { + async (fullMatch, startInst, type, template, args, body, endInst) => { args = args.trim(); let parsedArgs = {}; if (args) { @@ -52,12 +54,26 @@ async function updateTemplateInstantiations( return fullMatch; } } - let { text: templateText } = await readPage(template); - let templateFn = Handlebars.compile( - replaceTemplateVars(templateText, pageName), - { noEscape: true } - ); - let newBody = templateFn(parsedArgs); + let templateText = ""; + if (template.startsWith("http://") || template.startsWith("https://")) { + try { + let req = await fetch(template); + templateText = await req.text(); + } catch (e: any) { + templateText = `ERROR: ${e.message}`; + } + } else { + templateText = (await readPage(template)).text; + } + let newBody = templateText; + // if it's a template (note a literal "include") + if (type === "template") { + let templateFn = Handlebars.compile( + replaceTemplateVars(templateText, pageName), + { noEscape: true } + ); + newBody = templateFn(parsedArgs); + } return `${startInst}\n${newBody.trim()}\n${endInst}`; } ); @@ -79,10 +95,19 @@ export async function updateMaterializedQueriesOnPage( return false; } let newText = await updateTemplateInstantiations(text, pageName); + let tree = await parseMarkdown(newText); + newText = await replaceAsync( newText, queryRegex, - async (fullMatch, startQuery, query, body, endQuery) => { + async (fullMatch, startQuery, query, body, endQuery, index) => { + let currentNode = nodeAtPos(tree, index + 1); + if (currentNode?.type !== "CommentBlock") { + // If not a comment block, it's likely a code block, ignore + return fullMatch; + } + // console.log("Text slice", newText.substring(index, index + 100)); + let parsedQuery = parseQuery(replaceTemplateVars(query, pageName)); console.log("Parsed query", parsedQuery); diff --git a/website/πŸ”Œ Backlinks.md b/website/πŸ”Œ Backlinks.md index 682969c9..aebda378 100644 --- a/website/πŸ”Œ Backlinks.md +++ b/website/πŸ”Œ Backlinks.md @@ -5,6 +5,24 @@ repo: https://github.com/Willyfrog/silverbullet-backlinks author: Guillermo VayΓ‘ ``` + +# SilverBullet plug for Backlinks + Provides access to pages that link to the one currently being edited. -Use the `Show Backlinks for current page` command to toggle. +## Wait, SilverBullet? + +If you don't know what it is, check its [webpage](https://silverbullet.md), but if +you want me to spoil the fun: it is an extensible note taking app with markdown and plain files at its core +(well... there is a bit of magic in there too, but what good it would be without a little magic?) + +## Installation + +Open (`cmd+k`) your `PLUGS` note in SilverBullet and add this plug to the list: + +```yaml +- https://github.com/Willyfrog/silverbullet-backlinks/releases/download/v0.2/backlinks.plug.json +``` + +Then run the `Plugs: Update` command and off you go! + \ No newline at end of file diff --git a/website/πŸ”Œ Ghost.md b/website/πŸ”Œ Ghost.md index 66a35d61..eb26f990 100644 --- a/website/πŸ”Œ Ghost.md +++ b/website/πŸ”Œ Ghost.md @@ -4,10 +4,10 @@ uri: github:silverbulletmd/silverbullet-ghost/ghost.plug.json repo: https://github.com/silverbulletmd/silverbullet-ghost author: Zef Hemel ``` + +# Ghost plug for Silver Bullet -Very basic plug to publish pages and posts onto the [Ghost](https://ghost.org) platform - -## Configuration +Note: Still very basic, to use: In your `SETTINGS` specify the following settings: @@ -25,4 +25,14 @@ And in your `SECRETS` file: This will assume the naming pattern of `posts/my-post-slug` where the first top-level heading (`# Hello`) will be used as the post title. -Commands to use `Ghost: Publish` \ No newline at end of file +Commands to use `Ghost: Publish` + +## Installation +Open your `PLUGS` note in SilverBullet and add this plug to the list: + +``` +- github:silverbulletmd/silverbullet-ghost/ghost.plug.json +``` + +Then run the `Plugs: Update` command and off you go! + diff --git a/website/πŸ”Œ Git.md b/website/πŸ”Œ Git.md index a191bb37..7b1265dd 100644 --- a/website/πŸ”Œ Git.md +++ b/website/πŸ”Œ Git.md @@ -4,15 +4,27 @@ uri: github:silverbulletmd/silverbullet-github/github.plug.json repo: https://github.com/silverbulletmd/silverbullet-github author: Zef Hemel ``` + +# SilverBullet plug for Git +Very basic in functionality, it assumes you have git configured for push and pull in your space. What it does, roughly speaking: -The git plug provides very basic β€œgit sync” functionality, it assumes you have git configured for push and pull in your space. It offers two commands: +`Git : Sync`: +* Adds all *.md files in your folder to git +* It commits them with a "Snapshot" commit message +* It `git pull`s changes from the remote server +* It `git push`es changes to the remote server -* `Git : Sync`: - * Adds all *.md files in your folder to git - * It commits them with a "Snapshot" commit message - * It `git pull`s changes from the remote server - * It `git push`es changes to the remote server +`Git: Snapshot`: +* Asks you for a commit message +* Commits + +## Installation +Open your `PLUGS` note in SilverBullet and add this plug to the list: + +``` +- github:silverbulletmd/silverbullet-git/git.plug.json +``` + +Then run the `Plugs: Update` command and off you go! + -* `Git: Snapshot`: - * Asks you for a commit message - * Commits diff --git a/website/πŸ”Œ Github.md b/website/πŸ”Œ Github.md index b4142bec..acbac407 100644 --- a/website/πŸ”Œ Github.md +++ b/website/πŸ”Œ Github.md @@ -4,9 +4,30 @@ uri: github:silverbulletmd/silverbullet-github/github.plug.json repo: https://github.com/silverbulletmd/silverbullet-github author: Zef Hemel ``` - + +# SilverBullet plug for Github Provides Github events, notifications and pull requests as query sources using SB's query mechanism +## Installation +Open your `PLUGS` note in SilverBullet and add this plug to the list: + +``` +- github:silverbulletmd/silverbullet-github/github.plug.json +``` + +Then run the `Plugs: Update` command and off you go! + +## Configuration +This step is optional for anything but the `gh-notification` source, but without it you may be rate limited by the Github API, + +To configure, add a `githubToken` key to your `SECRETS` page, this should be a [personal access token](https://github.com/settings/tokens): + + ```yaml + githubToken: your-github-token + ``` + +## Query sources + * `gh-event` required filters in the `where` clause: * `username`: the user whose events to query * `gh-pull` @@ -29,4 +50,5 @@ Example uses: Where the `template/gh-pull` looks as follows: - * ({{state}}) [{{title}}]({{html_url}}) \ No newline at end of file + * ({{state}}) [{{title}}]({{html_url}}) + diff --git a/website/πŸ”Œ Mattermost.md b/website/πŸ”Œ Mattermost.md index 14000894..cdb528be 100644 --- a/website/πŸ”Œ Mattermost.md +++ b/website/πŸ”Œ Mattermost.md @@ -4,9 +4,19 @@ uri: github:silverbulletmd/silverbullet-mattermost/mattermost.plug.json repo: https://github.com/silverbulletmd/silverbullet-mattermost author: Zef Hemel ``` - + +# Mattermost plug for Silver Bullet Provides a `mm-saved` query provider (and maybe more in the future). Please follow the installation, configuration sections, and have a look at the example. +## Installation +Open your `PLUGS` note in SilverBullet and add this plug to the list: + +``` +- github:silverbulletmd/silverbullet-mattermost/mattermost.plug.json +``` + +Then run the `Plugs: Update` command and off you go! + ## Configuration You need two bits of configuration to make this plug work. In `SETTINGS` provide the `mattermostUrl` and `mattermostDefaultTeam` settings, they default to the following: @@ -40,31 +50,6 @@ Note that the `{[Unsaved]}` "button" when clicked, will unsave the post automati Example uses (using the `template/mm-saved` template above): -[lindy.isherwood](mattermost://community.mattermost.com/private-core/pl/u8ospw14ptg47fystidzudigjw) in **R&D Meeting** at 2022-07-22 {[Unsave]}: -> #### [Meeting Recording](https://mattermost.zoom.us/rec/share/e0CmkZr_1xaW0Zd-7N-saD5fir9pmjJy6-xw4JZ7el7IMIUUUr99FiC2WePmBZDw.HRzSgvBjxhsPGQWo) -> -> Access Passcode: `wq$!BA6N` - ---- -[harrison](mattermost://community.mattermost.com/core/pl/akuzqwdm4if7fdmajjb94hpm5c) in **** at 2022-07-20 {[Unsave]}: - -> Hey Zef. Can we chat about the Affirm issue a bit when I get back? From what I've gathered, Devin's told customer support that the issue in Chromium isn't something we can reasonably fix, and while I don't feel like that's anything I should be worried about since it's out of my area, I keep getting ... (More) - ---- -[zef.hemel](mattermost://community.mattermost.com/core/pl/k41cfgdbhfg5unm8yx1cjkh8ty) in **** at 2022-07-20 {[Unsave]}: - -> I'll have to get back to this tomorrow. Filename says "arm64" though - ---- -[zef.hemel](mattermost://community.mattermost.com/core/pl/9e1ha9yzzpdm9ffhu4od65yykc) in **** at 2022-07-19 {[Unsave]}: - -> Agreed. Thinking what are better indicators than what we already ask. I’ll reach out. - ---- -[zef.hemel](mattermost://community.mattermost.com/private-core/pl/hh79ikgfzb8zmb4ezjuow7a1mw) in **Team: Web Platform** at 2022-07-15 {[Unsave]}: - -> @webplatform in yesterday’s 1:1 with @harrison we came up with the concept of β€œtheme weeks” to solve our problem of scheduling _important but not urgent_ work. Examples are: looking at performance improvements, cleaning/fixing lingering bugs from our backlog, working on accessibility tickets, perfor ... (More) - ---- - \ No newline at end of file + + diff --git a/website/πŸ”Œ Mount.md b/website/πŸ”Œ Mount.md index d66484e5..7fb2ed1e 100644 --- a/website/πŸ”Œ Mount.md +++ b/website/πŸ”Œ Mount.md @@ -4,8 +4,18 @@ uri: github:silverbulletmd/silverbullet-mount/mount.plug.json repo: https://github.com/silverbulletmd/silverbullet-mount author: Zef Hemel ``` + +# Mounting of external systems into SB +Enables mounting of external folders or SB instances into your space. -Enables mounting of external folders or SB instances into your space mounted under a `πŸšͺ` prefix. +## Installation +Open your `PLUGS` note in SilverBullet and add this plug to the list: + +``` +- github:silverbulletmd/silverbullet-mount/mount.plug.json +``` + +Then run the `Plugs: Update` command and off you go! ## Configuration Create a `MOUNTS` page: @@ -19,15 +29,4 @@ Create a `MOUNTS` page: path: http://some-ip:3000 password: mypassword ``` - -This will make these available under `πŸšͺ docs/` and `πŸšͺ remote/` respectively. - -## Features -* Auto translates internal wiki links (prefixes with prefix) and removes prefix upon save - -## To do -* [ ] Handle queries - * `page` and `link` query needs to dynamically add/remove a `and name =~ /^πŸšͺ PREFIX/` clause) - * `task` same but with `page` check -* [x] Add `file:` support -* [x] Add `http:`/`https:` support + diff --git a/website/πŸ”Œ Plugs.md b/website/πŸ”Œ Plugs.md index 092d4bec..4022a4e6 100644 --- a/website/πŸ”Œ Plugs.md +++ b/website/πŸ”Œ Plugs.md @@ -4,12 +4,12 @@ Plugs are an extension mechanism (implemented using a library called `plugos` th ## Directory -* [[πŸ”Œ Git]] by **Zef Hemel** ([repo](https://github.com/silverbulletmd/silverbullet-github)) +* [[πŸ”Œ Backlinks]] by **Guillermo VayΓ‘** ([repo](https://github.com/Willyfrog/silverbullet-backlinks)) * [[πŸ”Œ Ghost]] by **Zef Hemel** ([repo](https://github.com/silverbulletmd/silverbullet-ghost)) +* [[πŸ”Œ Git]] by **Zef Hemel** ([repo](https://github.com/silverbulletmd/silverbullet-github)) * [[πŸ”Œ Github]] by **Zef Hemel** ([repo](https://github.com/silverbulletmd/silverbullet-github)) * [[πŸ”Œ Mattermost]] by **Zef Hemel** ([repo](https://github.com/silverbulletmd/silverbullet-mattermost)) * [[πŸ”Œ Mount]] by **Zef Hemel** ([repo](https://github.com/silverbulletmd/silverbullet-mount)) -* [[πŸ”Œ Backlinks]] by **Guillermo VayΓ‘** ([repo](https://github.com/Willyfrog/silverbullet-backlinks)) ## How to develop your own plug