Using Hugo + Netlify

Wed, Apr 22, 2020

This site has been through several iterations, hosting providers, and tools. For a while now, I’ve been happy with using Hugo as a static site generator. This gets me plain HTML and a lot more flexibility with how the hosting actually works.

At my day job, I help operate the corporate cloud with lots of VMs, and lots of complexity. When I’m running stuff for myself, I’d rather maximize simplicity This doesn’t just apply at home – it just applies so much more so when using the limited time I have for myself. .

After sprucing up my own site, I decided to review how I was hosting things. I’ve considered something like IPFS, but then I’d need to setup/manage a few servers running the IPFS daemon, an ipfs web gateway, pipelines to publish – so much yak shaving Don’t get me wrong, IPFS is really neat and I think it is something that should exist, I’m just not ready to plunk down my time into that rabbit hole – yet! . I just want to host a couple HTML files!

Instead, I’ve gone with Netlify since they handle all the complexity for me. As an added bonus, they’re free for my usage tier. I don’t have analytics right now, but they do offer a tool I might pay for their analytics as a means to pay for what I use. I don’t get enough traffic to justify their $45 dollar cost. that uses the data from their CDN for tracking instead of modifying the site.

I don’t even need to write any deployment code either. I just hooked it up to this site’s github repo and they took care of the rest. To deploy, I just commit and push my changes to master – it doesn’t get much simpler than that.

This all should reduce the friction of writing. To that end, I’ve made a simple script that’s in my repo to make new articles easier. One of the things I don’t like about the standard hugo new post/title is that it creates the content file without the date as a prefix. I find that prefixing things with the date makes it easier for me, since I don’t need to make such pithy titles and then my files are listed in order.

#!/usr/bin/env ruby

fail 'an argument is required' unless ARGV.length >= 1

type, title = ARGV.join(' ').split('/')
title.gsub!(/[^[A-Za-z0-9]]+/, '-')
name = ["%Y-%m-%d"), 

fail "file already exists" if File.file?("content/#{type}/#{name}.md")

if system("hugo new #{type}/#{title}.md")
  if File.rename("content/#{type}/#{title}.md", "content/#{type}/#{name}.md")
    exec("nvim content/#{type}/#{name}.md")

It probably could use a few variables and handle errors a bit better, but that is kind of like work. I keep it as ./bin/create which means I just execute I mostly write go and keep the compiled binaries in a ./bin directory. I’ve added it to my $PATH so I can have locally scoped scripts/binaries. create post/something clever. This saves me the extra mileage on my fingers to generate the date prefix and removes just a little bit more friction from writing.