Templates 2.0 (#636)
Templates 2.0 and a whole bunch of other refactoring
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
This library is highly recommended for everybody to import immediately. It provides a lot of functionality you’ll likely appreciate (and may be used to having out of the box, if you’re longer-term SilverBullet user).
|
||||
|
||||
Some random examples:
|
||||
* [[Table of Contents]] and [[Linked Mentions]]
|
||||
* All the slash commands you know and love, ranging from `/h1` to `/task` to `/table` to `/code` to `/query` to `/template` to `/today` to...
|
||||
* Some useful general purpose pages such as [[Library/Core/Page/Maintenance]] and [[Library/Core/Page/Template Index]].
|
||||
|
||||
# Installation
|
||||
To import this library, run the {[Library: Import]} command in your SilverBullet space and enter:
|
||||
|
||||
!silverbullet.md/Library/Core/
|
||||
|
||||
# Included templates
|
||||
```query
|
||||
template
|
||||
where name =~ /^{{escapeRegexp @page.name}}\//
|
||||
render [[Library/Core/Query/Template]]
|
||||
```
|
||||
|
||||
# Included utility pages
|
||||
```query
|
||||
page
|
||||
where name =~ /^{{escapeRegexp @page.name}}\// and tags != "template"
|
||||
render [[Library/Core/Query/Page]]
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
description: Define a new Page Template
|
||||
tags: template
|
||||
hooks.newPage:
|
||||
suggestedName: Library/Personal/Page/
|
||||
forPrefix: Library/Personal/Page/
|
||||
confirmName: true
|
||||
frontmatter: |
|
||||
tags: template
|
||||
displayName: "|^|"
|
||||
hooks.newPage:
|
||||
suggestedName: Library/Personal/Page/
|
||||
---
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
description: "Create a quick note"
|
||||
tags: template
|
||||
hooks.newPage:
|
||||
suggestedName: "Inbox/{{today}} {{time}}"
|
||||
confirmName: false
|
||||
command: "Quick Note"
|
||||
key: "Alt-Shift-n"
|
||||
---
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
tags: template
|
||||
hooks.newPage:
|
||||
suggestedName: "template/snippet/"
|
||||
confirmName: true
|
||||
forPrefix: template/snippet/
|
||||
description: Define a new Snippet Template
|
||||
frontmatter: |
|
||||
tags: template
|
||||
hooks.snippet:
|
||||
name: "|^|"
|
||||
---
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
tags: template
|
||||
description: Define a new template
|
||||
hooks.newPage:
|
||||
suggestedName: template/
|
||||
forPrefix: template/
|
||||
frontmatter:
|
||||
tags: template
|
||||
---
|
||||
|^|
|
||||
@@ -0,0 +1,36 @@
|
||||
We would like to keep our space clean, these are some tools that help you do that.
|
||||
|
||||
# Broken links
|
||||
This shows all internal links that are broken.
|
||||
|
||||
```template
|
||||
query: |
|
||||
link where toPage and pageExists(toPage) = false
|
||||
template: |
|
||||
{{#if .}}
|
||||
{{#each .}}
|
||||
* [[{{ref}}]]: broken link to [[{{toPage}}]]
|
||||
{{/each}}
|
||||
{{else}}
|
||||
No broken links, all good!
|
||||
{{/if}}
|
||||
```
|
||||
|
||||
# Conflict copies
|
||||
These are pages that have conflicted copies (as a result of sync), have a look at them as well as their original (non-conflicted versions) and decide which one to keep.
|
||||
|
||||
```template
|
||||
query: |
|
||||
page where name =~ /\.conflicted\.\d+$/
|
||||
select
|
||||
name as conflictedName,
|
||||
replace(name, /\.conflicted\.\d+$/, "") as cleanName
|
||||
template: |
|
||||
{{#if .}}
|
||||
{{#each .}}
|
||||
* [[{{cleanName}}]]: confict copy [[{{conflictedName}}]]
|
||||
{{/each}}
|
||||
{{else}}
|
||||
No conflicting pages!
|
||||
{{/if}}
|
||||
```
|
||||
@@ -0,0 +1,47 @@
|
||||
This page lists all templates currently available in your space.
|
||||
|
||||
# New Page
|
||||
$newPage
|
||||
These [[!silverbullet.md/Page Templates]] are available through the {[Page: From Template]} command.
|
||||
|
||||
```query
|
||||
template where hooks.newPage render [[Library/Core/Query/Template]]
|
||||
```
|
||||
|
||||
# Snippets
|
||||
$snippets
|
||||
These can be used as [[!silverbullet.md/Snippets]] via [[!silverbullet.md/Slash Commands]]:
|
||||
|
||||
```query
|
||||
template where hooks.snippet render [[Library/Core/Query/Template]]
|
||||
```
|
||||
|
||||
# Widgets
|
||||
$widgets
|
||||
Widgets can either be automatically attached to the top or bottom of pages (matching certain criteria) or used inline via [[!silverbullet.md/Live Templates]].
|
||||
|
||||
## Top
|
||||
```query
|
||||
template
|
||||
where hooks.top
|
||||
order by order
|
||||
render [[Library/Core/Query/Template]]
|
||||
```
|
||||
|
||||
## Bottom
|
||||
```query
|
||||
template
|
||||
where hooks.bottom
|
||||
order by order
|
||||
render [[Library/Core/Query/Template]]
|
||||
```
|
||||
|
||||
## Inline
|
||||
Use these as `page` in [[!silverbullet.md/Live Templates]] to render useful things in your pages:
|
||||
|
||||
```query
|
||||
template
|
||||
where name =~ /\/Widget\// and hooks.top = null and hooks.bottom = null
|
||||
order by order
|
||||
render [[Library/Core/Query/Template]]
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
tags: template
|
||||
description: A page reference link as a list item
|
||||
---
|
||||
* [[{{name}}]]
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
tags: template
|
||||
description: Generic task template that supports updating the status back in the origin page
|
||||
---
|
||||
* [{{state}}] [[{{ref}}]] {{name}}
|
||||
@@ -0,0 +1,5 @@
|
||||
#template
|
||||
* [[{{ref}}]] {{description}}
|
||||
{{#if usage}}
|
||||
* **Usage:** {{usage}}
|
||||
{{/if}}
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
description: Insert a fenced code block
|
||||
tags: template
|
||||
hooks.snippet.slashCommand: code
|
||||
---
|
||||
```|^|
|
||||
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
tags: template
|
||||
description: Insert Frontmatter
|
||||
hooks.snippet:
|
||||
slashCommand: frontmatter
|
||||
insertAt: page-start
|
||||
command: "Insert Frontmatter"
|
||||
---
|
||||
---
|
||||
|^|
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
tags: template
|
||||
description: Make this a level 1 heading
|
||||
hooks.snippet:
|
||||
slashCommand: h1
|
||||
match: "^#*\\s*"
|
||||
---
|
||||
#
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
tags: template
|
||||
description: Make this a level 2 heading
|
||||
hooks.snippet:
|
||||
slashCommand: h2
|
||||
match: "^#*\\s*"
|
||||
---
|
||||
##
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
tags: template
|
||||
description: Make this a level 3 heading
|
||||
hooks.snippet:
|
||||
slashCommand: h3
|
||||
match: "^#*\\s*"
|
||||
---
|
||||
###
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
tags: template
|
||||
description: Make this a level 4 heading
|
||||
hooks.snippet:
|
||||
slashCommand: h4
|
||||
match: "^#*\\s*"
|
||||
---
|
||||
####
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
tags: template
|
||||
description: Insert a horizontal rule
|
||||
hooks.snippet.slashCommand: hr
|
||||
---
|
||||
---
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
tags: template
|
||||
description: Insert a "note" admonition
|
||||
hooks.snippet.slashCommand: note-admonition
|
||||
---
|
||||
> **note** Note
|
||||
> |^|
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
description: Insert a live query
|
||||
tags: template
|
||||
hooks.snippet.slashCommand: query
|
||||
---
|
||||
```query
|
||||
|^|
|
||||
```
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
tags: template
|
||||
description: Insert a table
|
||||
hooks.snippet.slashCommand: table
|
||||
---
|
||||
| Header A | Header B |
|
||||
|----------|----------|
|
||||
| Cell A|^| | Cell B |
|
||||
@@ -0,0 +1,10 @@
|
||||
---
|
||||
tags: template
|
||||
description: Turn the current line into a task
|
||||
hooks.snippet:
|
||||
slashCommand: task
|
||||
matchRegex: "^(\\s*)[\\-\\*]?\\s*(\\[[ xX]\\])?\\s*"
|
||||
command: "Turn into task"
|
||||
key: "Ctrl-q t"
|
||||
---
|
||||
$1* [ ]
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
description: Insert an inline template
|
||||
tags: template
|
||||
hooks.snippet.slashCommand: "template"
|
||||
---
|
||||
```template
|
||||
page: "[[|^|]]"
|
||||
```
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
tags: template
|
||||
description: "Today's date"
|
||||
hooks.snippet.slashCommand: today
|
||||
---
|
||||
{{today}}
|
||||
@@ -0,0 +1,6 @@
|
||||
---
|
||||
tags: template
|
||||
description: "Tomorrow's date"
|
||||
hooks.snippet.slashCommand: tomorrow
|
||||
---
|
||||
{{tomorrow}}
|
||||
@@ -0,0 +1,7 @@
|
||||
---
|
||||
description: Insert a "warning" admonition
|
||||
tags: template
|
||||
hooks.snippet.slashCommand: warning-admonition
|
||||
---
|
||||
> **warning** Warning
|
||||
> |^|
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
description: >
|
||||
Adds a convenient "Copy to my space" button to any
|
||||
template found via federation
|
||||
tags: template
|
||||
hooks.bottom.where: 'name =~ /^!/ and tags="template"'
|
||||
---
|
||||
# Template actions
|
||||
* {[Page: Copy|Copy to my space]}: use this template in your space by making a local copy of it (and tweaking it as you like)
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
description: Adds Linked Mentions to pages
|
||||
tags: template
|
||||
hooks.bottom.where: 'true'
|
||||
---
|
||||
```template
|
||||
# We need to escape handlebars directives here, since we're embedding
|
||||
# this template into a template (INCEPTION)
|
||||
template: |
|
||||
{{escape "#if ."}}
|
||||
# Linked Mentions
|
||||
{{escape "#each ."}}
|
||||
* [[{{escape "ref"}}]]: `{{escape "snippet"}}`
|
||||
{{escape "/each"}}
|
||||
{{escape "/if"}}
|
||||
query: |
|
||||
link where toPage = "{{@page.name}}" and page != "{{@page.name}}"
|
||||
```
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
tags: template
|
||||
description: |
|
||||
Shows all tasks that contain a link the current page. For instance a task that references `[[John]]` in its name, would appear on the `John` page.
|
||||
---
|
||||
|
||||
```query
|
||||
task where name =~ /\[\[{{escapeRegexp @page.name}}\]\]/ where done = false render [[Library/Core/Query/Task]]
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
description: Adds a Table of Contents to pages
|
||||
tags: template
|
||||
hooks.top:
|
||||
where: 'true'
|
||||
# Show all the way at the top
|
||||
order: 0
|
||||
---
|
||||
```toc
|
||||
minHeaders: 3
|
||||
```
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
tags: template
|
||||
description: Queries all tasks tagged with a specific tag.
|
||||
usage: Pass in the tag to filter on as the `value` of this template
|
||||
---
|
||||
|
||||
```query
|
||||
task where tags = "{{.}}" and done = false render [[Library/Core/Query/Task]]
|
||||
```
|
||||
@@ -0,0 +1,28 @@
|
||||
This library contains some useful page templates for journalers. Want to easily create a daily or weekly note? These templates can get you started. Instantiate them via {[Page: From Template]}.
|
||||
|
||||
# Installation
|
||||
To import this library, run the {[Library: Import]} command in your SilverBullet space and enter:
|
||||
|
||||
!silverbullet.md/Library/Journal/
|
||||
|
||||
# Included templates
|
||||
```query
|
||||
page
|
||||
where name =~ /^{{escapeRegexp @page.name}}\//
|
||||
render [[Library/Core/Query/Page]]
|
||||
```
|
||||
|
||||
# Tips
|
||||
Do you want your space’s start page to always be either your daily or weekly note? You can!
|
||||
|
||||
To set the _daily note_ as the default page, set the following in [[SETTINGS]]:
|
||||
|
||||
```yaml
|
||||
indexPage: "Journal/Day/{{today}}"
|
||||
```
|
||||
|
||||
And for the _weekly note_:
|
||||
|
||||
```yaml
|
||||
indexPage: "Journal/Week/{{weekStart}}"
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
description: "Your daily note template"
|
||||
tags: template
|
||||
hooks.newPage:
|
||||
suggestedName: "Journal/Day/{{today}}"
|
||||
confirmName: false
|
||||
openIfExists: true
|
||||
forPrefix: "Journal/Day/"
|
||||
command: "Open Daily Note"
|
||||
key: "Alt-Shift-d"
|
||||
---
|
||||
* |^|
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
description: "Open your weekly note page"
|
||||
tags: template
|
||||
hooks.newPage:
|
||||
suggestedName: "Journal/Week/{{weekStart}}"
|
||||
forPrefix: "Journal/Week/"
|
||||
confirmName: false
|
||||
openIfExists: true
|
||||
command: "Open Weekly Note"
|
||||
key: "Alt-Shift-w"
|
||||
---
|
||||
# Goals
|
||||
* |^|
|
||||
Reference in New Issue
Block a user