Broken link improvements

I’ve grown to like this workflow of mentioning topics before they have a page, and then filling out the most used broken links, to focus on useful ideas. With the previous way broken links were implemented as a command in broken_links.ts, I have made some small changes to make this work nicer for me:

Main features I got from this:

  • sort by number of mentions
    • then order by page
  • see the missing topics as red links so I can fill them out with a click

But while thinking whether I should make a PR, the lightspeed development team already changed it into a template. :joy:

I agree that template is more accessible than code and would like to follow, but I can’t think of a way to get this with a query, how could I approach it?

This is your lightspeed development team speaking.

I got this far:

link where pageExists(toPage) = false select toPage
render [[Library/Core/Page/Maintenance/Non Existing Page]]

Where that Non Existing Page template contains:

tags: template
## [[{{toPage}}]]
template: |
  {{escape "#each ."}}
  * [[{{escape "ref"}}]]
  {{escape "/each"}}
query: |
   link where toPage = "{{toPage}}" select ref

Looks like this: headings are non-existing pages (although don’t appear red yet), bulleted lists are locations where the broken links appear.

The escaping is kind of messy, but this is what currently needs to be done to use templates within templates like this.

I have to admit that [[Library/Core/Page/Maintenance]] is perfectly fine for me as it looks

Thanks, this works perfectly! For the record, the new Maintenance page is really good, just thought of this as a good case study. And I did get somehting new — I couldn’t figure out query within query, but templates in templates are the way to go.

Regarding the links not being red, could it be the same issue as showing [[ ]] in table of contents where headers are links?

Seems different than Different formatting in live query/template than in normal text · Issue #530, that looked like CSS and this is like different parsing?

Also, should I stop posting issues in random posts here and go to GitHub myself?

EDIT: Page links rendered differently inside “live” output · Issue #665 · silverbulletmd/silverbullet

Yeah, everything “live” is rendered differently than in the (editable parts) of the editor. So effectively I have to implement all that twice. Indeed, reporting issues in GH issues would make it easier to track. Thanks!

So,how would you replace this template to the new template system?

Right. Can’t do it very nicely yet, have to add one more thing to #each loops: the ability to assign the item to a variable.

Ok, this works on Edge (not in 0.7.0 but will in 0.7.1):

{{#each @brokenLink in {link where !pageExists(toPage) select toPage}}}
## {{@brokenLink.toPage}}
{{#each @originLink in {link where toPage = @brokenLink.toPage select ref}}}
  * [[{{@originLink.ref}}]]

Not bad huh?


Hats off, essentially how I’d write this in any other language (including in a Plug)

1 Like

My sense is that if I add a few more things, the need to write custom plugs decreases dramatically.