Merge pull request #169 from DC1TC/dc1tc/optimize-script-fix
Some checks failed
Deploy Docs / deploy-gh-pages (push) Has been cancelled

Fix optimize.sh script error and revert dependency update attempt.

Revert previous attempt of updating the yarn dependencies. I did not understand the failure when I tried that.

The issue was an E2BIG error in optimize.sh caused by too many arguments.
Instead of passing the full list of images once, use smaller batches of images paths passed to sharp-cli.
This commit is contained in:
DC1TC 2026-05-13 21:36:09 +02:00 committed by GitHub
commit f9d0c8762f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1679 additions and 1383 deletions

View file

@ -1,3 +1,28 @@
#!/bin/bash #!/bin/bash
set -euo pipefail
echo "running image optimization" echo "running image optimization"
npx --yes sharp-cli resize 1200 --withoutEnlargement true --optimise true --progressive true --withMetadata false --failOn none --input $(find ./docs \( -name cache -prune \) -o -name '*' -type f -exec file {} \; | awk -F: '{ if ($2 ~/[Ii]mage|EPS/) print $1}') --output "{dir}/{base}"
ROOT_DIR="./docs"
BATCH_SIZE=73
# Build a list of image files (skip "cache" directories)
file_list=$(mktemp)
find "$ROOT_DIR" \( -name cache -prune \) -o -type f -exec file {} \; \
| awk -F: '{ if ($2 ~ /[Ii]mage|EPS/) print $1 }' > "$file_list"
# Process in batches using xargs; each invocation gets up to $BATCH_SIZE files
sparp_cli_cmd() {
local batch_args=("$@")
npx --yes sharp-cli resize 1200 \
--withoutEnlargement true --optimise true --progressive true --withMetadata false --failOn none \
--input "${batch_args[@]}" --output "{dir}/{base}"
}
export -f sparp_cli_cmd
# Use xargs to call a shell wrapper which forwards the args into xargs_cmd
# The "_" is the placeholder $0 so filenames become $1..$N inside the wrapper
xargs -r -n "$BATCH_SIZE" bash -c 'sparp_cli_cmd "$@"' _ < "$file_list"
# Cleanup
rm -f "$file_list"

3035
yarn.lock

File diff suppressed because it is too large Load diff