Website automation: write a post for the future, and then publish it on the correct date.

automation jekyll websites

Sometimes I write something for a future date, and I want to then

  • generate my website so I can see the new pages and check them,
  • set up a script to regenerate on the date of the next new post.

Ok, so this worked out to be easier than I thought. First, generate the site to see the future posts, something like

jekyll serve --future

Take a look around. Is it good? Then create a script that will regenerate the site on the date of a new post. I created a script in a directory _scripts. It looks like

#!/bin/sh

jekyll build -d docs/

git -C ~/amy-tabb.github.io add .

git -C ~/amy-tabb.github.io commit -am "automated build"

git -C ~/amy-tabb.github.io push origin master

jekyll build -d docs/ generates the site in development mode, and sets the destination to docs/.

The git -C ~/amy-tabb.github.io **** commands specify from which directory to run git, see this SO answer.

I then use a single use cron job to run the script, Red Hat:

chmod _scripts/build-and-push-script.sh

at 0:04 -f _scripts/build-and-push-script.sh

The at command creates a one-time cron job that will run at 0:04, or 4 minutes past midnight. The only new published pages are those dated for tomorrow.

© Amy Tabb 2018 - 2023. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.