Skip to content

Astro, fix .md in links

New Course Coming Soon:

Get Really Good at Git

Using Obsidian to edit my Markdown files, I’ve started to link lessons using Obsidian’s own internal linking.

It’s great because with Obsidian link tracking I can move a file around, change folder or filename, and links don’t break.

Links however use a .md extension, since we’re linking markdown files here.


So since I’m using Astro, links don’t work as they point to a URL ending with .md.

I found this rehype plugin for Astro:

It fixes this exact problem and I’m so grateful this exists, but didn’t (at the time of writing) install on Astro 3, required Astro 2. Maybe now it’s updated.

Anyway since it’s a single file I copied the file locally and imported in my Astro config.

Only thing I noticed is, maybe because I use content collections, my content collection path was prepended to URLs now, so I hardcoded a little custom fix in the code that only works in my use case, but well, job done.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!
→ Read my Astro Tutorial on The Valley of Code

Here is how can I help you: