Minimising friction for blogging with Hugo

I was pretty inspired that Levlaz was inspired by Derek Sivers’ post about OpenBSD. While I was hanging out in my terminal trying to remember how to get a blog post published with my super cool static site generating tool (Hugo), I was reminded that I needed to minimise friction for posting here.

So I wrote a shell script to make it super easy to edit and publish a blog post:


if [ $1 = "new" ];
  if [ $2 ];
    cd ~/projects/ && hugo new post/$ && \
      /usr/bin/open -a "/Applications/Google" 'http://localhost:1313' && \
      code content/post/$ && hugo server --cleanDestinationDir
    echo "No post name specified"
elif [ $1 = "publish" ];
  if [ $POST ];
    echo "Are you sure you want to publish $POST?"
    select yn in "Yes" "No"; do
      case $yn in
       Yes ) cd ~/projects/ && \
             git add content/post/$ && \
             git commit -m "Publish $POST" && \
             git push; return;;
        No ) return;;
    echo "No post env var set"
  echo "First argument must be 'new' or 'publish'"

I saved this to /usr/local/bin/ and added to my aliases like so:

alias blog-post='. /usr/local/bin/'

Note the ‘dot space’ which runs the script under the running shell so that we can set the post title as an env var for use when publishing the post later. So now I can type blog-post new having-the-best-day-of-my-life from anywhere in my terminal to:

Now I can write my blog post and saving the file will give an instant preview in the browser.

When I’m done I go back to the terminal and hit ctrl+c to stop the development server.

Now I can type blog publish which will check that I want to publish the post, and if I choose yes, create a commit and push to GitHub. Since I’m using Netlify, this will trigger a rebuild of my site and the post will be live.

Summary of blog publishing workflow

This makes me pretty happy since the only thing I wasn’t liking about using a static site generator was the friction involved in publishing posts. Now that I’ve removed that, I can’t wait to share more geeky stuff with the world.

comments powered by Disqus