This week I set out to come up with a way to automatically published future-dated posts to your website.
At first, I was looking at the static post scheduler from Serverless. This is a neat solution, but I didn’t like the need to create a pull request in order to publish the post. Especially considering Hugo already respects the publishdate parameter to determine if it should publish a post or not, it seemed a little redundant to also schedule the publish date in a PR.
The solution I came up with is to future-date posts that I want to publish in the future, and then just automatically run a rebuild+redeploy of the site at regular intervals.
The first solution is to use a CircleCI workflow to automatically run your deployment, which is super easy to set up if you’re already deploying with CircleCI (I wrote an article about that too!)
The second solution is a serverless function that will work with any CI tool you have hooked up to your Github repo, because it just pushes a commit at the interval you specify. Maybe it’s not the most elegant solution, but it’s pretty universal. (Do I get bonus points for writing it in Go?)
If you’ve been trying to figure out how to schedule posts with your Hugo site, I hope you find this useful!
I’ve never been a big user of scheduled blog posts. For what topics do you guys/gals use scheduled posts? For instance, only special anniversary posts or also regular content?
I don’t use scheduled posts, but I schedule to rebuild my site everyday so that this page has the most current “last updated” dates (fetched using GitHub/Gitlab API via getJSON).
Thanks for writing this, @dwalkr. I’m currently porting seattlereviewofbooks.com to Hugo, and we’ll both need a friendly editor, and a future publishing solution — our entire site is run on future publishing. I’ll look into some of these options when I’m ready to figure that part out.
I typically don’t use them. However, I do tend to write posts in splurges since one idea will kick off a load of others. It is generally best for SEO purposes, if you are seen to be posting regularly. So if you care about such things, you can write a bunch of posts when you feel inspired but spread the dates out then keep rebuilding daily.
I do the same thing and it works great! I set my build time to 3 AM since it was before anyone here would wake up and care, and it was past midnight for editors who like to burn the midnight oil.
We use it for upcoming events, usually some number of days before the event. We also use this for regular posts along with an editorial calendar and future content planning.
Thanks for the comments. I like the idea of scheduling posts in advance, and automatically rebuild the website at certain intervals. But I’m not a big fan of all the cache purges that are needed to make that work. I need my website to be quick too.
This is a good point. The shotgun solution is easy, but something more targeted (like a script that could know if/when there are scheduled posts to publish) wouldn’t deplete the cache so often
@dwalkr thanks for the post about scheduling circleci builds. That made it simple to schedule a daily build so I can undraft finished posts with a future date.
FWIW, I use a similar approach, except with the GitHub CI to host Hugo via Cloudflare Pages. The advice on the Cloudflare Discord was to use a webhook, so like @kaushalmodi I have a IFTTT that simply pings my CF Pages webhook in the middle of the night to rebuild.
(and when I’m getting ready to commit, I locally build with hugo server --buildFuture.)
what i want to set up next is for my preview builds on CF Pages to also run with the --buildFuture flag, so then I can QC everything on a staging server before the prod server updates…just haven’t gotten around to this yet.
If you’re looking for a different solution that rebuilds your site at the specific time a post has to go live or a post has to be expired, here’s a tutorial:
Been using this solution for over a year, and finally wrote about it!