summarylogtreecommitdiffstats
path: root/svgo.sh.in
blob: 9b306236ba1a563f41485e8787647bd463aa5a99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/bash
#
#   svgo.sh - Compress SVG files using optsvg
#

[[ -n "$LIBMAKEPKG_TIDY_SVGO_SH" ]] && return
LIBMAKEPKG_TIDY_SVGO_SH=1

LIBRARY=${LIBRARY:-'@libmakepkgdir@'}

source "$LIBRARY/util/message.sh"
source "$LIBRARY/util/option.sh"

packaging_options+=('svgo')
tidy_modify+=('tidy_svgo')

tidy_svgo() {
  if check_option "svgo" "y"; then
    msg2 "$(gettext "Optimizing SVG images...")"
    local svg
    find . -type f -iname "*.svg" 2>/dev/null | while read -r svg ; do
      [ $(jobs -p|wc -l) -gt $(getconf _NPROCESSORS_ONLN) ] && wait -n
      if [[ $(file --brief --mime-type "$svg") = 'image/svg' ]]; then
        { svgo "${SVGOFLAGS[@]}" "$svg" &>/dev/null ||
          warning "$(gettext "Could not optimize SVG image : %s")" "${svg/$pkgdir\//}"; } &
      fi
    done
    wait
  fi
}