Schedule static page deploys on Netlify with IFTTT
This blog is a static website hosted on Netlify. As static site builder, I use the awesome Hugo, which is written in Go and amazingly fast. This page with currently more than 300 pages build in less than 500ms.
But as the name “static” suggest - just static files that are served by a simple HTTP server - it doesn’t have a dynamic backend with the option to schedule posts, so scheduling isn’t possible the same way it is with systems like WordPress.
But this isn’t an impossible problem. When you are hosting your site on Netlify too, you can easily setup a webhook with IFTTT (If This Then That), which is a service that let’s you automate various things and let’s you connect many different services with each other.
A webhook is basically a plain simple HTTP call. When the trigger in IFTTT executes, IFTTT calls the specified URL. Netlify offers support for such webhooks and starts a rebuild of your website, whenever a special URL is called.
This isn’t really scheduling, but it allows to trigger an hourly / daily / weekly… rebuild of your site. And because Hugo by default just builds pages that have a date from the past, pages with a date in the future aren’t getting build and such don’t appear when someone visits your website.
All you have to do for this are the following steps:
- Go to the settings of your page in the Netlify dashboard and search the section “Build & Deploy” - “Build Hooks”.
- Create a new “Build Hook” and give it a reasonable name.
- Copy the URL displayed (it’s something like “api.netlify.com/build_hooks/…”).
- Go to IFTTT and create a new applet.
- As “this” service choose “Date & Time” and configure as wished.
- As “then” service choose “Webhook”, insert the copied URL, change the method to “POST”, choose “application/json” as content type and as body paste “{}”.
- Just “Finish” and you’re done. 🎉
I for example use IFTTT to trigger a daily deploy of my website at 9 AM. And if I wrote a post I just set the date to 9 AM for the day I plan to make it public. This article was published the same way. 😄