---
# Reference these scripts as follows to integrate them into your jobs:

# before_script:
#   - !reference [".web:optimize", images]
#   - !reference [".web:optimize", other]
#   - hugo --environment production

# Place these where they are best suited. For example, optimize images _before_
# building your site, so any postprocessing on them will be done with more
# efficient images.

variables:
  WEB_OPTIMIZE_IMAGE_FIND_REGEX: .*.jpe?g
  WEB_OPTIMIZE_IMAGE_QUALITY: 85
  WEB_OPTIMIZE_IMAGE_MAX_WIDTH: 2560
  WEB_OPTIMIZE_IMAGE_DEFAULT_ARGS: -strip -interlace Plane

.web:optimize:
  images:
    - |
      if command -v mogrify >/dev/null; then
        find . -type f -regex ${WEB_OPTIMIZE_IMAGE_FIND_REGEX} -exec mogrify -verbose ${WEB_OPTIMIZE_IMAGE_DEFAULT_ARGS} -quality ${WEB_OPTIMIZE_IMAGE_QUALITY} -resize ${WEB_OPTIMIZE_IMAGE_MAX_WIDTH}x\> {} \;
      else
        echo "[!] Imagemagick not available. Not optimizing images."
      fi
