Deploying Hugo on Netlify through Github

2019/10/27

Outline

Steps to quickly publish a site on Netlify using the static site generator Hugo and Github.

We will use Hugo to locally generate a site. We then push it to Github. Netlify watches the Github repo and deploys the static website when done.

The accounts

You’ll need to set up the following accounts:

  1. Github
  2. Netlify
  3. If desired, you need a domain (like example.com). Otherwise you’ll have your site hosted at name-of-thesite.netlify.com, which should also work just fine.

Getting started

  1. Install Hugo. I’m on Ubuntu so it was a matter of sudo apt install hugo. For your OS, check out this page.
  2. Install Git, if not already installed. Again, for me on Ubuntu this means sudo apt install git-all. For your OS, check this page.
  3. Create a new hugo site. Navigate to the place where you want it, and perform hugo new site <directoryname>. This will create your site in the given directory.
  4. Select a theme from the Hugo themes page.
  5. Follow the instructions at Netlify’s documentation page.

Honestly, I was going to post an entire 23-step how-to. But then I realised I just followed Netlify’s instructions and they work great. Make sure that you choose the right build command. When using Hugo, it’s probably just hugo. Now, whenever I push changes to the content directory to Github, or edit pages directly in the Github web interface, Netlify builds my website and publishes it. Awesome stuff, all for free!

Issues

Custom domain not properly resolving

I use an external DNS provider for my custom domain. I used to run my own web hosting, but decided not to do that going forward. During the set up, I had intermittent issues with the domain working and not working. Since it sometimes worked, at first I did not suspect DNS propagation times had anything to do with it. After some patience, turns out, it did.

So, if you custom domain does not work immediately, give it some time. 24 hours should do it, as that’s a default TTL for many DNS records.