Obsidian Publish

I want to keep all my writing inside an Obsidian vault

I still want to host my writing in a Hugo website

Obsidian vault is just a collection of interlinked markdown files with some links to other files. Same as the Content folder in a Hugo project. So, lets do it.

Problems with Obsidian => Hugo

So the problem I have with my idea for “writing all my content as an Obsidian notebook and publishing as a Hugo site” is that the notes in Obsidian constructs file system links, because why wouldn’t it.

If I link to another markdown file in the blog directory the path of the markdown link would be “blog/file.md”. If I was writing a similar link while writing a new blog post in a more normal workflow, the path of the markdown link would be “/blog/file/”

If I just build my notes to Hugo, none of the intra-note links will work. I can solve this with a couple of sed scripts to a slash to each and of the path and remove the “.md” extension. I’ll need to consider image links also, but I think it can be done.

In addition, hugo has no concept of backlinks, so any such fanciness that Obsidian displays to me, will not exist when published. To help with this I’ve written some go code that will walk through my notes and build a json file that maps the source and target of every markdown link. My hugo theme can then use the json file to render backlinks. Loop through the each record in the json file and if the target link matches the current page then print the source link to the page.

How and where to run these workarounds

The gist of this, however, is that I have to run a couple of scripts on me content before pushing to github or before the build step in the github action.

Running the sed scripts to modify the links can’t be done inside my notes repo because while it fixes the links for the website, it breaks them for Obsidian. So, ideally this would happen in a github action.

Building the json file of backlink data can’t, I don’t think, be done in the github action because the file it creates needs to be strored in the data folder in the repository, and while I havent looked into it, I can only assume that while executing an action that is triggered by a push to a branch you can’t push to said branch. Because recursion is fun.

My current thinking is that it doesn’t matter if the backlinks are occasionally stale but if I fun the backlink generation before each push from my laptop it will be fine. Adding content away from my laptop will not cause a backlinks to be updated but will be fixed next time I’m at my laptop. This could be acceptable I think.