Observation
In this blog’s previous Wordpress incarnation, I found post creation very cumbersome. As I use Obsidian in my day-to-day note taking, it seemed logical to me to see was it feasible to use as a blog input mechanism.
Hypothesis
It should be possible to use Obsidian notes to generate blog posts automatically.
Initial Research
On researching this, I found that this is actually a relatively popular method of blogging, but with several caveats that didn’t quite gel with what I was trying to achieve.
I want to use my existing main Obsidian vault to allow for posts to organically emerge from existing notes. Most of the examples I came across online used a dedicated vault for their blogs (e.g. Steph Ango, Obsidian CEO).
Obsidian Publish is another option, where you can pay a subscription to easily publish your vault. Again, not what I had in mind, seeing that I’m already paying for the web server.
I came across Hugo, which works to convert markdown files to generate static websites - this seems like the right tool for the job. I will need to do some pre-processing of the markdown files to clean them up before running through Hugo, however.
Moving the static files to the server requires a sync tool, for which I think rsync is the best option.
Procedure
- Set up git repository to manage “blog” project on local computer.
- Set up rsync between local computer and server
- Use Hugo to create project skeleton
- Create python module within repository.
- Run python module as needed to publish.
Python Module Details
- Read each post from blog directory within Obsidian vault.
- Process each post
- create directory for each post in target destination
- converting image embeds
- formatting cover image references correctly
- moving image files into the correct directories
- cleaning up document links to only allow relative links within the blog directory (e.g. if a file outside of blog directory is linked to, it’s converted to plain text)
- Misc other tidy-up
- Trigger Hugo build process to generate static web pages
- Trigger rsync process to move static files to web server.
Discussion
This was an interesting process and I did lots of experimentation and learning within the Python code.
For now this works well, but there’s definitely still room for optimisation, e.g. maybe moving Hugo to the web server and running on file modification and having something like SyncThing run to allow direct publishing from Obsidian without having to run Python code manually.
