Preparing for 0.5.6

pull/570/head
Zef Hemel 2023-11-19 12:18:16 +01:00
parent 7503110e84
commit 063c49effb
9 changed files with 59 additions and 23 deletions

View File

@ -4,6 +4,8 @@ import { resolvePath } from "$sb/lib/resolve.ts";
import { indexObjects, queryObjects } from "./api.ts";
import { ObjectValue } from "$sb/types.ts";
const pageRefRegex = /\[\[([^\]]+)\]\]/g;
export type LinkObject = {
ref: string;
tags: string[];
@ -123,9 +125,40 @@ export async function indexLinks({ name, tree }: IndexTreeEvent) {
links.push(link);
return true;
}
// Also index links used inside query and template fenced code blocks
if (n.type === "FencedCode") {
const codeInfo = findNodeOfType(n, "CodeInfo")!;
if (!codeInfo) {
return false;
}
const codeLang = codeInfo.children![0].text!;
if (codeLang === "template" || codeLang === "query") {
const codeText = findNodeOfType(n, "CodeText");
if (!codeText) {
return false;
}
const code = codeText.children![0].text!;
const matches = code.matchAll(pageRefRegex);
for (const match of matches) {
const pageRefName = resolvePath(name, match[1]);
const pos = codeText.from! + match.index! + 2;
links.push({
ref: `${name}@${pos}`,
tags: ["link"],
toPage: pageRefName,
page: name,
snippet: extractSnippet(pageText, pos),
pos: pos,
asTemplate: true,
inDirective: false,
});
}
}
}
return false;
});
// console.log("Found", backLinks, "page link(s)");
// console.log("Found", links, "page link(s)");
await indexObjects(name, links);
}

View File

@ -33,6 +33,9 @@ export async function widget(
if (templatePage.startsWith("[[")) {
templatePage = templatePage.slice(2, -2);
}
if (!templatePage) {
throw new Error("No template page specified");
}
templateText = await space.readPage(templatePage);
}

View File

@ -2,9 +2,13 @@ An attempt at documenting the changes/new features introduced in each
release.
---
## Next
## 0.5.6
* Various optimization and bug fixes
* Experimental idea: [[Template Sets]]
* The `Alt-Shift-n` key was previously bound to both {[Page: New]} and {[Quick Note]}. That wont work, so now its just bound to {[Quick Note]}
* The `Alt-q` command is now bound to the new {[Live Queries and Templates: Refresh All]} command refreshing all [[Live Queries]] and [[Live Templates]] on the page. This is to get yall prepared to move away from directives.
* Its time to get ready for the removal of directives, and convert your entire space over using (one time operation). Please backup your space before you do: {[Directive: Convert Entire Space to Live/Templates]}
* Its likely that version 0.6.0 **will remove directives**, so please switch over to live queries and templates, e.g. using...
* The new {[Directive: Convert Entire Space to Live/Templates]} command, which will (attempt) to convert all uses of directives in your space automatically (backup your space before, though, just in case)
---

View File

@ -51,7 +51,7 @@ upnext
Although you may want to render it using a template such as [[template/tasks/task] instead:
```query
upnext render [[template/tasks/task]]
upnext render [[template/task]]
```
## taskstate

View File

@ -1,8 +1,11 @@
> **warning** Experimental
> This is still an experimental idea. These templates may change, be renamed etc. prepare yourself for breakage.
This is an attempt at collecting useful, reusable templates so you dont have to reinvent the wheel.
The most convenient ways to use them is using [[Federation]]. This will synchronize these templates into your space and make them available for use instantly.
While you may just copy & paste these templates to your own space, the most convenient ways to use them is using [[Federation]]. This will synchronize these templates into your space and make them available for use instantly.
To set this up, add this to your [[SETTINGS]]:
To set this up, add the following this to your [[SETTINGS]]:
```yaml
federate:
@ -12,11 +15,11 @@ federate:
If you dont want to sync _all_ these templates, you can use more specific URIs, e.g.
```yaml
federate:
- uri: silverbullet.md/template/tasks
- uri: silverbullet.md/template/task
```
to just get the `tasks` stuff.
to just get the `task` stuff.
To reference a template, use the federation syntax, e.g. `[[!silverbullet.md/template/tasks/task]]`.
To reference a template, use the federation syntax, e.g. `[[!silverbullet.md/template/task]]`.
## Maintenance
```query
@ -33,7 +36,7 @@ render [[template/documented-template]]
```
## Tasks
```query
template where name =~ /^template\/tasks/
template where name =~ /^template\/task/
order by order
render [[template/documented-template]]
```

View File

@ -1,4 +0,0 @@
#template
```query
task where tags = "{{.}}" and done = false render [[template/tasks/task]]
```

View File

@ -1,2 +1,6 @@
#template
---
tags: template
description: generic task template that supports updating the status back in the origin page
order: 1
---
* [{{state}}] [[{{ref}}]] {{name}}

View File

@ -1,7 +0,0 @@
---
tags: template
description: generic task template that supports updating the status back in the origin page
order: 1
---
* [{{state}}] [[{{ref}}]] {{name}}

View File

@ -47,7 +47,7 @@ There is a [[!silverbullet.md/template/tasks/task]] template you can use to rend
Try it (by clicking on the checkbox inside of the directive):
```query
task where page = "{{@page.name}}" and name = "Remote toggle me" render [[template/tasks/task]]
task where page = "{{@page.name}}" and name = "Remote toggle me" render [[template/task]]
```
* [ ] Remote toggle me