- stage
- budding
- planted
- 2026-11-10
- tags
- [astro, markdown]
budding— Taking shape. Cleaned up, still growing.
Wiki-links and backlinks in Astro
A small Markdown plugin for double-bracket links, and a build-time scan for what links back.
Two pieces make the garden’s links work, and neither needs a dependency beyond what Astro already ships.
Links: a Markdown plugin
src/lib/wiki-links-plugin.ts is a plugin for Sätteri, the Markdown processor Astro 7 uses by default. It visits every text node and replaces [[note-id]] in text nodes with a link to /garden/note-id/. [[blog/post-id]] and [[til/note-id]] point at the other sections, and [[note-id|some text]] sets the link text. Without it, the plugin reads the target’s title from its frontmatter.
Code blocks and inline code are separate node types, so [[examples]] inside backticks are left alone. (Remark plugins still work, but only after installing @astrojs/markdown-remark and switching the whole site back to the older unified pipeline.)
Backlinks: scan the bodies
Every content entry keeps its raw Markdown in entry.body. At build time, getLinkGraph() in src/lib/garden.ts scans each post, TIL and note for wiki-links and ordinary Markdown links to internal pages, and records the line each link sits on. That line becomes the preview under “linked from”.
Links to notes that don’t exist yet
A link to an unwritten note, like graph-view, is dimmed and not clickable. The garden index lists these under ls --not-planted-yet, which doubles as a list of ideas.
The check runs when the page is rendered, not when the Markdown is parsed. Astro caches parsed Markdown by file content, so a parse-time check would keep showing a link as missing after its note was written.
Open questions
- Link previews on hover would make following an idea faster.
- A graph view looks nice, but I’m not sure it helps anyone read.
$ grep -rl "[[wiki-links-and-backlinks]]" ~ # linked from
- garden/content-layer-order.mdAstro's content layer doesn't keep file order
Then sort by after querying. Still to check: whether the glob loader has the same behaviour, and whether it's documented anywhere. Related: Wiki-links and backlinks in Astro relie…
- garden/how-this-garden-works.mdHow this garden works
Notes link to each other with double brackets, and every note ends with the pages that link to it, so you can follow an idea in either direction. The details are in Wiki-links and…