Skip to content

Instantly share code, notes, and snippets.

@denisazevedo
Last active April 6, 2018 04:48
Show Gist options
  • Select an option

  • Save denisazevedo/a0c30525059312c3f8df7e2a787a4878 to your computer and use it in GitHub Desktop.

Select an option

Save denisazevedo/a0c30525059312c3f8df7e2a787a4878 to your computer and use it in GitHub Desktop.
publish_to_ghpages - Script to publish Hugo site to GitHub Pages
#!/bin/sh
# Script based on https://gohugo.io/hosting-and-deployment/hosting-on-github/
DIR=$(dirname "$0")
UPSTREAM=${1:-origin}
cd $DIR/..
if [[ $(git status -s) ]]
then
echo "The working directory is dirty. Please commit any pending changes."
exit 1;
fi
echo "Deleting old publication"
rm -rf public
mkdir public
git worktree prune
rm -rf .git/worktrees/public/
echo "Checking out gh-pages branch into public"
git worktree add -B gh-pages public $UPSTREAM/gh-pages
echo "Removing existing files"
rm -rf public/*
echo "Generating site"
hugo
# TODO add the date to the commit msg
echo "Updating gh-pages branch"
cd public && git add --all && git commit -m "Publishing to gh-pages (publish.sh)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment