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:
parent
f4d43d1e35
commit
7bd1a14ef5
3 changed files with 24 additions and 6 deletions
8
scripts/brotli-wrapper.sh
Normal file
8
scripts/brotli-wrapper.sh
Normal 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
|
||||
|
|
@ -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
9
scripts/ect-wrapper.sh
Normal 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
|
Loading…
Reference in a new issue