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.
I wrote an article for Forestry talking about the strategy and provided two solutions for accomplishing this: Automatically Publish Scheduled Posts For Your Static Site
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!
DIsclaimer: I work for Forestry.io