Skip to content

Instantly share code, notes, and snippets.

@victoriadrake
Created May 22, 2018 15:42
Show Gist options
  • Save victoriadrake/7d45a8f2ac5cc53743ad34eec8950182 to your computer and use it in GitHub Desktop.
Save victoriadrake/7d45a8f2ac5cc53743ad34eec8950182 to your computer and use it in GitHub Desktop.
A makefile that regenerates the public/ folder for Hugo sites, optimizes images and prepares the git commit for GitHub Pages.
SHELL:=/bin/bash
BASEDIR=$(CURDIR)
OUTPUTDIR=$(BASEDIR)/public
optipng = find $(OUTPUTDIR) -name '*.png' -print0 | xargs -0 -P8 -n2 optipng -o5 -strip all -quiet
optijpg = find $(OUTPUTDIR) -name '*.jpg' -print0 | xargs -0 -P8 -n2 jpegoptim --strip-all -m30 -q
site:
@echo "Deleting files from old publication"
rm -rf $(OUTPUTDIR)/*
@echo "Generating site"
hugo
@echo "Optimizing images"
$(call optijpg)
$(call optipng)
@echo "Preparing commit"
cd $(OUTPUTDIR)/ && git add . && git status && git commit -m "$(m)"
@victoriadrake
Copy link
Author

If you use a custom domain with GitHub Pages, ensure that your Hugo site contains the CNAME file inside root/static/. You can also put your README.md there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment