[Bjonnh.net]# _

# Articles/ Generate a hugo (golang) website when doing git push

Published on
Categories: computer Tags: hugo git hooks lazyness

Tonight, I played with git hooks. Because I wanted to be able to regenerate the website remotely just by doing a push to a specific branch of the website repo.

By adding on the remote side in the bare git repo in hooks/post-receive (that you have to make executable):

read oldrev newrev refname
if [ $refname = "refs/heads/$BRANCH" ]; then
echo "Copying the git"
echo "Generating the website"
hugo -s $SOURCE_FOLDER -d $DEST_FOLDER --cacheDir $SOURCE_FOLDER/.cache

Just replace /src with a folder your git user has access to, replace /www by the place your web server will look and production by the branch that contains the production version.

I added the cacheDir option, because I don’t want executable stuff in /tmp so pygments was complaining that it was enforced (complaining with a void error message, I had to strace it).