Created
May 22, 2018 15:42
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" |
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
Prerequisites:
What this Makefile does:
public/
, leaving hidden files (like.git
) intacthugo
commandoptipng
andjpegoptim
to understand these)public/
, creates a new commit with your messageUsage
Do
make site m="<your message>"
This Makefile does not do
git push
for you. If everything looks ok after the Makefile runs, do this manually.