Templates 2.0 (#636)

Templates 2.0 and a whole bunch of other refactoring
This commit is contained in:
Zef Hemel
2024-01-20 19:16:07 +01:00
committed by GitHub
parent 0a6a0016a2
commit f30b1d3418
171 changed files with 2038 additions and 1628 deletions
@@ -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: "|^|"
---
+10
View File
@@ -0,0 +1,10 @@
---
tags: template
description: Define a new template
hooks.newPage:
suggestedName: template/
forPrefix: template/
frontmatter:
tags: template
---
|^|
+36
View File
@@ -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]]
```
+5
View File
@@ -0,0 +1,5 @@
---
tags: template
description: A page reference link as a list item
---
* [[{{name}}]]
+5
View File
@@ -0,0 +1,5 @@
---
tags: template
description: Generic task template that supports updating the status back in the origin page
---
* [{{state}}] [[{{ref}}]] {{name}}
+5
View File
@@ -0,0 +1,5 @@
#template
* [[{{ref}}]] {{description}}
{{#if usage}}
* **Usage:** {{usage}}
{{/if}}
+8
View File
@@ -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"
---
---
|^|
---
+8
View File
@@ -0,0 +1,8 @@
---
tags: template
description: Make this a level 1 heading
hooks.snippet:
slashCommand: h1
match: "^#*\\s*"
---
#
+8
View File
@@ -0,0 +1,8 @@
---
tags: template
description: Make this a level 2 heading
hooks.snippet:
slashCommand: h2
match: "^#*\\s*"
---
##
+8
View File
@@ -0,0 +1,8 @@
---
tags: template
description: Make this a level 3 heading
hooks.snippet:
slashCommand: h3
match: "^#*\\s*"
---
###
+8
View File
@@ -0,0 +1,8 @@
---
tags: template
description: Make this a level 4 heading
hooks.snippet:
slashCommand: h4
match: "^#*\\s*"
---
####
+6
View File
@@ -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
> |^|
+8
View File
@@ -0,0 +1,8 @@
---
description: Insert a live query
tags: template
hooks.snippet.slashCommand: query
---
```query
|^|
```
+8
View File
@@ -0,0 +1,8 @@
---
tags: template
description: Insert a table
hooks.snippet.slashCommand: table
---
| Header A | Header B |
|----------|----------|
| Cell A|^| | Cell B |
+10
View File
@@ -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* [ ]
+8
View File
@@ -0,0 +1,8 @@
---
description: Insert an inline template
tags: template
hooks.snippet.slashCommand: "template"
---
```template
page: "[[|^|]]"
```
+6
View File
@@ -0,0 +1,6 @@
---
tags: template
description: "Today's date"
hooks.snippet.slashCommand: today
---
{{today}}
+6
View File
@@ -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]]
```