I ran in to a little issue with my
publish.sh script that I use to automatically publish my site with Hugo. I wipe out the
public folder and then rebuild the site with Hugo. After that is done, the
public folder is synced to the web host, using the
--delete option. The problem arises if Hugo encounters an error. The site isn’t rebuilt but the now empty
public folder is synced, wiping out the website.
The script now checks Hugo’s exit code, and will only sync if the code is
0. I hope that helps someone!
if ! command -v /snap/bin/hugo &> /dev/null
echo "Hugo not found. Install with:"
echo "sudo snap install hugo"
echo "Building at `date`"
if [ ! -d "themes/ananke" ]; then
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
echo "Clear out public.."
[[ -d "public" ]] || mkdir "public"
rm -r public/*
echo "Building site..."
# If something goes wrong building the site, exit the script!
if [ ! $? -eq 0 ]; then
echo "Something is wrong..."
echo "Set up some RSS stuff..."
cp public/posts/index.xml public/feed/
cp public/tags/podcast/index.xml public/feed/podcast/
echo "Adding build date..."
date > public/built.txt
hostname >> public/built.txt
echo "Uploading site..."
rsync -e ssh -avp --progress --delete public/ gozgeek:gozgeek.com/
Mention the link on social media or like the link in a post on social media for the mention to show up here.