1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-11-10 00:12:09 +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" # 2. "gzip" or "brotli"
# 3. ECT zopfli compression level # 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 set -e -u
dirname="$(dirname "$0")"
output_dir="$1" output_dir="$1"
format="$2" 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" \)' 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 if [ "$format" = "gzip" ]; then
compress_level="$3" # compression level should be the third argument
find_compressible -exec ect -quiet -"$compress_level" -gzip {} \; find_compressible | xargs -n1 sh "$dirname/ect-wrapper.sh" "${3-6}"
find_compressible -exec touch -r {} {}.gz \; elif [ "$format" = "brotli" ]; then
elif [ "$2" = "brotli" ]; then find_compressible | xargs -n1 sh "$dirname/brotli-wrapper.sh"
find_compressible -exec brotli -Z -- {} \;
fi 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