Build from github, tag the deploy, and optimize images for the web

Some configuration is required, replace the directories with your own and install the required tools: imagemagick, jpegoptim and jpegtran.

The end result is a tag on github letting you know when was the last deploy and slimmer files for the web without losing image quality.

Hope this helps someone :slight_smile:

eval $(ssh-agent); 
cd /YOUR-SOURCE-DIRECTORY/; git pull; git tag DEPLOY-`date +%Y-%m-%d_%H-%M` && git  push --tag
hugo --cleanDestinationDir;

# Optimize images
DIRS=$(/usr/bin/find /DIRECTORY-FOR-IMAGES-AFTER-BUILD/ -type d -print0 | xargs -0)

for d in $DIRS; do
	cd $d;
	echo $d;
	/usr/bin/find $d -maxdepth 1 -type f -name "*.jpeg" -or -name "*.jpg" -exec /usr/bin/convert {} -resize 500x500 -set filename:original %t %[filename:original]_500.jpg \;
/usr/bin/find $d -maxdepth 1 -type f -name "*.jpeg" -or -name "*.jpg" -exec sh -c '/usr/bin/jpegtran -outfile {}.out -copy none -optimize -perfect {}; mv {}.out {}' \; -exec chmod 644 {} \;
echo 'All done!'