Using a Shell Script to Automate the Building and Deploying of My Hugo Blog

blot.blog is powered by Hugo, which is static site generator. So basically my blog is a bunch of Markdown and other files that then gets ‘built’ into HTML, CSS, etc. files and then uploaded to the web. But the thing is, this all has to be done manually by command in the Terminal. It’s a pain and adds an extra layer of friction when it comes to blogging. And it also means it’s a huge pain to update the blog via my phone.

So I’ve finally gotten around to automating it via a shell script to reduce this friction. Here’s what it does:

  • Hazel checks if there’s a Markdown file in my drafts folder with the word publish in it. If so, the script is run.
  • The script edits the ‘front matter’ metadata of the post by marking it as no longer a draft and inserting the current date and time.
  • Extracts the title from the post and renames the file as YYYY-MM-DD - blog-post-title.md and moves it into the non-drafts folder.
  • Builds the blog and deploys it to Amazon S3.
  • Does a git commit and push.

It’s worked well so far. And as the script runs on my always-on Mac mini I can write a post on my phone and all I have to do is add publish to the beginning of the file name to automatically publish it.

Hopefully this will mean I blog a bit more often.

(Here’s the code, if you’re interested)

Elliot Clowes @ec

✍️ Reply by email