Improve compress script
Generate zst and br files, then remove any that are actually larger than the source file
This commit is contained in:
parent
70e5b9bec7
commit
cf6e65cc03
16 changed files with 31 additions and 3 deletions
BIN
public/assets/css/app.css.zst
Normal file
BIN
public/assets/css/app.css.zst
Normal file
Binary file not shown.
Binary file not shown.
BIN
public/assets/css/colours.css.zst
Normal file
BIN
public/assets/css/colours.css.zst
Normal file
Binary file not shown.
BIN
public/assets/css/content.css.zst
Normal file
BIN
public/assets/css/content.css.zst
Normal file
Binary file not shown.
BIN
public/assets/css/fonts.css.zst
Normal file
BIN
public/assets/css/fonts.css.zst
Normal file
Binary file not shown.
BIN
public/assets/css/h-card.css.zst
Normal file
BIN
public/assets/css/h-card.css.zst
Normal file
Binary file not shown.
BIN
public/assets/css/indieauth.css.zst
Normal file
BIN
public/assets/css/indieauth.css.zst
Normal file
Binary file not shown.
BIN
public/assets/css/layout.css.zst
Normal file
BIN
public/assets/css/layout.css.zst
Normal file
Binary file not shown.
BIN
public/assets/css/notes.css.zst
Normal file
BIN
public/assets/css/notes.css.zst
Normal file
Binary file not shown.
BIN
public/assets/css/variables.css.zst
Normal file
BIN
public/assets/css/variables.css.zst
Normal file
Binary file not shown.
BIN
public/assets/frontend/is-land.js.zst
Normal file
BIN
public/assets/frontend/is-land.js.zst
Normal file
Binary file not shown.
BIN
public/assets/frontend/snow-fall.js.zst
Normal file
BIN
public/assets/frontend/snow-fall.js.zst
Normal file
Binary file not shown.
BIN
public/assets/highlight/zenburn.css.zst
Normal file
BIN
public/assets/highlight/zenburn.css.zst
Normal file
Binary file not shown.
BIN
public/assets/js/app.js.zst
Normal file
BIN
public/assets/js/app.js.zst
Normal file
Binary file not shown.
BIN
public/assets/js/auth.js.zst
Normal file
BIN
public/assets/js/auth.js.zst
Normal file
Binary file not shown.
|
@ -1,13 +1,41 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
if ! type fd &> /dev/null; then
|
||||
if ! (( $+commands[fd] )) &> /dev/null; then
|
||||
echo "fd not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! type brotli &> /dev/null; then
|
||||
if ! (( $+commands[brotli] )) &> /dev/null; then
|
||||
echo "brotli not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fd -e css -e js --search-path ./public/assets --type f -x brotli --force --best --output={}.br {}
|
||||
if ! (( $+commands[zstd] )) &> /dev/null; then
|
||||
echo "zstd not installed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make .br files
|
||||
fd --extension css --extension js --search-path ./public/assets --type f --exec brotli --force --best --output={}.br {}
|
||||
# Make .zst files
|
||||
fd --extension css --extension js --search-path ./public/assets --type f --exec zstd --quiet --force --ultra -22 --exclude-compressed {} -o {}.zst
|
||||
|
||||
# Remove files that actually got bigger!
|
||||
fd --extension br --extension zst --search-path ./public/assets --type f --exec sh -c '
|
||||
for file; do
|
||||
src="${file%.br}"
|
||||
src="${src%.zst}"
|
||||
if [ -f "$src" ]; then
|
||||
# Get file sizes using stat with cross-platform compatibility
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
file_size=$(stat -f%z "$file")
|
||||
src_size=$(stat -f%z "$src")
|
||||
else
|
||||
file_size=$(stat -c%s "$file")
|
||||
src_size=$(stat -c%s "$src")
|
||||
fi
|
||||
# Compare sizes and conditionally echo rm command
|
||||
[ "$file_size" -ge "$src_size" ] && rm "$file"
|
||||
fi
|
||||
done
|
||||
' _ {}
|
||||
|
|
Loading…
Add table
Reference in a new issue