1
0
Fork 0
mirror of https://git.sr.ht/~seirdy/seirdy.one synced 2024-09-19 20:02:10 +00:00
seirdy.one/scripts/compress.sh
Rohan Kumar cb26956bca
Internal: improve scripts
- I forgot to compress xhtml files. fix that.

- Stylistic change: remove unnecessary brace expansions
- Don't repeatedly append to a file; run commands in a different scope
  and write all at once.

Move Nu HTML validator filtering into a shell script:
- Return a bad exit code if validation errors are found after filtering
- Remove null-ish values from the JSON output; the final output *should*
  be an empty string, since nothing should be reported.
2022-06-02 17:18:13 -07:00

20 lines
499 B
Bash

#!/bin/sh
# takes three args:
# 1. output dir
# 2. "gzip" or "brotli"
# 3. ECT zopfli compression level
set -e -u
output_dir="$1"
format="$2"
alias find_compressible='find "$output_dir" -type f \( -name "*.html" -o -name "*.xhtml" -o -name "*.xml" -o -name "*.webmanifest" -o -name "*.*.svg" \)'
if [ "$format" = "gzip" ]; then
compress_level="$3"
find_compressible -exec ect -quiet -"$compress_level" -gzip {} \;
elif [ "$2" = "brotli" ]; then
find_compressible -exec brotli -Z -- {} \;
fi