Automatic Blog Deploys

Automatic Blog Deploys

June 6, 2019

One of the first things I’ve been figuring out with this blog is how to schedule my posts. Because Hugo is a static site generator, you need to build and deploy the site at the time that you want to publish a post.

This is easy to do—we need (1) a recurring trigger and (2) that trigger needs to build and deploy the site. We’ll actually work through this backwards.

Build & Deploy

I’m using Netlify, so I’m going to be using a webhook that triggers my build and deploy. Under your site’s settings, find Build Hooks under the Build & deploy section. Just create a hook—this gives you a url to use to trigger redeploys.

If you’re self-hosted then there’s probably nothing for you to do here—you probably already have a command or script that you can call to trigger your deploy.

Recurring Trigger

Now we need some time-based trigger. Setting up a cron job would be one way to do this, but I’m not going down that route because I don’t have a dedicated server. Instead, I’m using IFTTT. Any automation tool will work fine.

I’m new to IFTTT, so I just created my own applet rather than trying to figure out how to use an existing one. You want to set the trigger to be Date & Time, allowing you to schedule things (in my case) every morning. You want to add a Webhooks action to make a web request. I left all of my fields as configurable by the user, but it doesn’t matter if you’re solely using your applet for yourself.

Once the applet’s created, you want to turn it on. If your fields are configurable by the user, make sure to set your redeploy frequency and your webhook. For Netlify, you just want to make an empty POST request to the build hook url that you generated.

That’s all there is to it. Stay tuned to see if this works—if so, you’ll see a new post on Monday!

Other Resources

comments powered by Disqus