Updated the compile script (v2) with extra flags and image optimization
parent
a9fbd27cad
commit
bcbf28b67b
66
compile
66
compile
|
@ -1,7 +1,65 @@
|
||||||
#/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [[ -d "public" ]]; then
|
# gmgsite compile script v2, merged with b-m-f's hugo-picture-optimization
|
||||||
rm -rf public/* && hugo
|
|
||||||
|
MAXIMUM_JPG_SIZE=250
|
||||||
|
PNG_OPTIMIZATION_LEVEL=2
|
||||||
|
|
||||||
|
optimize_images () {
|
||||||
|
|
||||||
|
# OG by b-f-m on GitHub
|
||||||
|
|
||||||
|
if hash exiftool 2>/dev/null; then
|
||||||
|
# remove exif data on all images in new_images
|
||||||
|
exiftool -all= public/ -r
|
||||||
else
|
else
|
||||||
mkdir public && hugo
|
echo "Install perl-image-exiftool to optimize images"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if hash jpegoptim 2>/dev/null; then
|
||||||
|
for image in $(find public/ -regextype posix-extended -iregex ".*\.(jpeg|jpg)"); do
|
||||||
|
# resize to width 1400 only if bigger than that
|
||||||
|
mogrify -resize '1400>' $image
|
||||||
|
# remove all metadata and try to optimize jpeg image to match the Maximum size defined above
|
||||||
|
jpegoptim --strip-all --size=$MAXIMUM_JPG_SIZE $image
|
||||||
|
done;
|
||||||
|
else
|
||||||
|
echo "Install jpegoptim to optimize JPEG images"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if hash optipng 2>/dev/null; then
|
||||||
|
for image in $(find public/ -regextype posix-extended -iregex ".*\.(png)"); do
|
||||||
|
# resize to width 1400 only if bigger than that
|
||||||
|
mogrify -resize '1400>' $image
|
||||||
|
# optimize PNG with a give level (higher = slower) and remove all metadata
|
||||||
|
optipng -clobber -strip all -o $PNG_OPTIMIZATION_LEVEL $image
|
||||||
|
done;
|
||||||
|
else
|
||||||
|
echo "Install optipng to optimize PNG images"
|
||||||
|
fi
|
||||||
|
|
||||||
|
find -type f -name '*_original' -delete
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
--no-clean-folder | -c)
|
||||||
|
mkdir public; hugo && optimize_images;;
|
||||||
|
|
||||||
|
--no-optimize-images | -i)
|
||||||
|
if [[ -d "public" ]]; then
|
||||||
|
rm -rf public/* && hugo
|
||||||
|
else
|
||||||
|
mkdir public && hugo
|
||||||
|
fi;;
|
||||||
|
|
||||||
|
--just-compile | -j)
|
||||||
|
mkdir public; hugo;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
if [[ -d "public" ]]; then
|
||||||
|
rm -rf public/* && hugo && optimize_images
|
||||||
|
else
|
||||||
|
mkdir public && hugo && optimize_images
|
||||||
|
fi;;
|
||||||
|
esac
|
||||||
|
|
Loading…
Reference in New Issue