#!/bin/bash
# Compress compressible formats with gzip for nginx's gzip_static

# - Markup/web formats
EXTENSIONS=("*.html" "*.htm" "*.xhtml" "*.xml" "*.css" "*.svg" "*.js" "*.wasm" "*.wml")
# - Text files
EXTENSIONS+=("*.txt")
# - Source code
EXTENSIONS+=("*.scad" "*.tex")
# - Sorta-compressible formats
EXTENSIONS+=("*.pdf" "*.doc" "*.stl")
# - Uncompressed bitmaps
EXTENSIONS+=("*.ico")
# - Uncompressed media
EXTENSIONS+=("*.wav" "*.riff")

BASE_DIR="_site/"

for EXT in "${EXTENSIONS[@]}"
do
	echo "GZip compressing $EXT..."
	find "$BASE_DIR" -iname "$EXT" | xargs --max-procs=0 -n1 gzip -9 -k -f
done


#I can afford to zoplify these
EXTENSIONS=("*.json")

for EXT in "${EXTENSIONS[@]}"
do
	echo "Zopflifying $EXT..."
	find "$BASE_DIR" -iname "$EXT" | xargs --max-procs=0 -n1 zopfli
done
