My New Blog (again)

Table of Contents

New year (almost), new me blog! It feels like this is the millionth time I made a new blog. My previous blog was really bad. I had to write blog posts inside a JSON file. Nothing at all was automated.

Recently I started using Obsidian to take notes. It’s just a markdown editor but with a fancy UI and some more features. Then one day I realized I could write my blog posts in Obsidian and have them automatically pushed to my website.

Pipeline

I need everything to be fully automated. I should be able to write a blog post in Obsidian and then a few minutes later it should appear on the website.

Here is how things work:

  1. I write a blog post in obsidian
  2. Hugo builds a static site
  3. Static site gets uploaded to GitHub
  4. GitHub pages deploys the site

Deployment

Initially, I was going to make my own backend that converts the markdown files to HTML files. That was until I found Hugo. Hugo does the exact thing I want and it also has a large selection of themes and it is really easy to deploy.

The nice thing about Hugo is that it builds a 100% static site. You can use the hugo server command to deploy it but you do have the option of using a web server of your choice.

Using GitHub Pages for deployment

At first, I was going to deploy the static site using a web server in my homelab. But then I realized I can just use GitHub pages to deploy it.

This was really simple. I just needed to deploy it using Pages and change the DNS entry in cloudflare.

Troubleshooting

I finished deploying it through GitHub Pages and I did everything I need but the website says there are no blog posts! This is odd as when running hugo server everything works. I even ran a custom web server on the public directory and that worked! This is really strange.

Then I realized my mistake. I forgot to commit the main branch to GitHub. The repository has 2 branches: the main branch, and the static branch. GitHub Pages will deploy from the static branch. I used a git command to send the public folder to the static branch and apparently I needed to commit on the main branch first.

Now everything works just fine!

Automating the writing process

The last challenge in building this blog is automatically getting my notes from Obsidian to GitHub. During testing, I used the rsync command to copy all of the blog posts from my notes folder to the Hugo folder. Then I would run the hugo command to build the site. I made a shell script that will do this for me automatically.

Now I need to figure out how to automatically run this shell script when I write a new blog post. I can just run the script every time but then I won’t be able to write posts on my laptop. I made a script using inotifywait to scan for file changes and run the script. However now I have encountered a problem. Git requires me to enter the password for my GPG key every time I want to commit something, including these blog posts. That means a popup will appear asking for my password every time I want to write a blog post. This was simple to bypass by disabling GPG signing for the commit.

Conclusion

Now that the new blog is done, hopefully I will be motivated to write more blog posts due to the ease of use. I have 2-way sync through Nextcloud on my desktop and laptop so in theory I will be able to write blog posts on my laptop just like I do on my desktop. See you all next year!