Adding incoming and outgoing links to my site
A quick write-up of another feature
Today I walk through adding incoming and outgoing links to my site. It wasn't particularly challenging, so this should be a quick one, but I think it really adds something nice to the site.
Backlinks are really popular in the "knowledge management tech" scene. I use them in my Obsidian Zettelkasten all the time. I find that it adds organic navigation and context to notes and helps me stay in the flow. It also promotes surprise connections. Since I publish all my notes online I thought it would be cool to add that functionality so that I (and others who read my site) can have a similar experience. It turns out it was relatively simple. Let's take a look.
Implementation
Given that this is a homebrew static(ish) site generator, my first step was to add some code to the CLI that would read and generate all the note links at build time.
let linked_note_ids = parse_links?;
if linked_note_ids.len > 0
Which first parses all the links out of the body of the note,
Then saves them all to the database.
// ... other plumbing ellided for the blog post
Which... yikes. Do as I say kids and not as I do. But here we are, and I feel relatively certain that I won't SQL inject myself in my notes. The other piece of "SaFeTy" here is that the regexes WIKILINK_REGEX and RENAME_REGEX pulls out a \d capture group into a Vec<u64>, so that makes it even less likely that something could get into that Vec<u64> for an injection attack.
Whatever, moving on.
Now we have all the links in the graph at build time so it's simple to query them and render them on the page.
And the askama template has a html/jinja-like syntax
{{ note.content|md }}
{% if links.incoming.len() > 0 %}
{%- include "icons/incoming.svg" -%}Links to this note
{% for link in links.incoming %}
{{link.id}} {{link.title}}
{% endfor %}
{% endif %}
{% if links.outgoing.len() > 0 %}
{%- include "icons/outgoing.svg" -%}Linked from this note
{% for link in links.outgoing %}
{{link.id}} {{link.title}}
{% endfor %}
{% endif %}
The hardest part for me in most of my website projects is design. I try to maintain a consistent look and feel on my site. It might not be your taste or style, but that's ok, it's my site and I like it. However, this means I want things to feel like they really belong and were thought through. Hopefully this feature meets that bar.
On large screens the links get put in their own column to take advantage of the real estate.

On smaller screens they wrap down below the main article. This works well on phones.

Linked from this note