1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-23 21:02:09 +00:00
seirdy.one/scripts/compress.sh

23 lines
606 B
Bash
Raw Normal View History

#!/bin/sh
# takes three args:
# 1. output dir
# 2. "gzip" or "brotli"
# 3. ECT zopfli compression level
2023-11-25 21:40:52 +00:00
# no pipefail here since there are no pipes.
set -e -u
output_dir="$1"
format="$2"
2023-08-21 18:27:07 +00:00
alias find_compressible='find "$output_dir" -type f \( -name "*.html" -o -name "*.txt" -o -name "*.xml" -o -name "*.webmanifest" -o -name "*.*.svg" -o -name "*.json" \)'
if [ "$format" = "gzip" ]; then
compress_level="$3"
find_compressible -exec ect -quiet -"$compress_level" -gzip {} \;
2022-09-01 03:35:37 +00:00
find_compressible -exec touch -r {} {}.gz \;
elif [ "$2" = "brotli" ]; then
find_compressible -exec brotli -Z -- {} \;
fi