weblate/scripts/optimize-svg
Michal Čihař 4316b6467f chore: introduce shellfmt for formatting shell files
This makes them look consistent and formatting is now enforced.
2024-10-04 15:03:44 +02:00

26 lines
796 B
Bash
Executable file

#!/bin/sh
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
optimize() {
# SVG optimization
scour --strip-xml-space --strip-xml-prolog --remove-metadata --no-line-breaks --enable-id-stripping --enable-comment-stripping --indent=none --remove-descriptive-elements "$icon" "$icon.tmp"
# Remove possible doctype
sed '/!DOCTYPE/d' < "$icon.tmp" > "$icon"
# Remove trailing newline (imgbot does this and we want to avoid fighting with it)
truncate -s -1 "$icon"
rm "$icon.tmp"
}
if [ $# -ne 0 ]; then
for icon in "$@"; do
optimize "$icon"
done
exit 0
fi
for icon in weblate/static/icons/*.svg weblate/static/auth/*.svg weblate/static/state/*.svg weblate/static/sort/*.svg; do
optimize "$icon"
done