1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-12-24 17:52:11 +00:00

avoid supressing compressor errors

This commit is contained in:
Rohan Kumar 2023-11-26 15:54:48 -08:00
parent f4d43d1e35
commit 7bd1a14ef5
No known key found for this signature in database
GPG key ID: 1E892DB2A5F84479
3 changed files with 24 additions and 6 deletions

View file

@ -0,0 +1,8 @@
#!/bin/sh
# compress a file with brotli if it isn't already compressed.
set -e -u
if [ ! -f "$1.br" ]; then
brotli -Z -- "$1"
fi

View file

@ -5,18 +5,19 @@
# 2. "gzip" or "brotli"
# 3. ECT zopfli compression level
# no pipefail here since there are no pipes.
#shellcheck disable=SC3040 # This only sets pipefail if it's available and otherwise does nothing
set -o pipefail 2>/dev/null || true
set -e -u
dirname="$(dirname "$0")"
output_dir="$1"
format="$2"
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 {} \;
find_compressible -exec touch -r {} {}.gz \;
elif [ "$2" = "brotli" ]; then
find_compressible -exec brotli -Z -- {} \;
# compression level should be the third argument
find_compressible | xargs -n1 sh "$dirname/ect-wrapper.sh" "${3-6}"
elif [ "$format" = "brotli" ]; then
find_compressible | xargs -n1 sh "$dirname/brotli-wrapper.sh"
fi

9
scripts/ect-wrapper.sh Normal file
View file

@ -0,0 +1,9 @@
#!/bin/sh
# compress a file with ect and preserve the mtime
# args: compression level and filename.
set -e -u
if [ ! -f "$2.gz" ]; then
ect -quiet -"$1" -gzip "$2"
touch -r "$2" "$2.gz"
fi