Using shell script to detect future Hugo articles.
So with Hugo you can post date content and it won’t show up until after that date. There is on caveat to this though, you have to rebuild the site. What if you don’t know what date that is? You can’t rebuild the site at that particular time. This is a script that will fix this.
Build the site.
First thing I do is remove the public directory to have a nice clean environment.
rm rm -Rf <hugo code>/public
Then I rebuild the site
hugo --source <hugo code> --quiet
Do a comparison to released code
Using the diff tool you can now do a folder/file comparison between the two. -r
does it recursively.
diff -rq <hugo code>/public <released code>
This will show you what is different and if nothing is different will then return a 0
.
Replace the new code
Using rsync we can now move the code over. --del
will delete target files if they don’t exist in the source.
rsync -a --del <hugo code>/public/ <released code>
Putting it all together
rm -Rf <hugo code>/public
hugo --source <hugo code> --quiet
if ! diff -rq <hugo code>/public <released code>
then
rsync -a --del <hugo code>/public/ <released code>
fi
I put this in a cron job and run this once a day right after midnight. This will release a new site if it has change.
One thing to note: If your Hugo versions are different then it will always release the site, so you need to either disable that option or make sure all your versions of Hugo are the same.