validate 627 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. set -e
  3. RET=0
  4. OUT=`mktemp`
  5. for fn in "$@"; do
  6. echo "Validating $fn..."
  7. echo
  8. case $fn in
  9. *.html)
  10. type="text/html"
  11. ;;
  12. *.css)
  13. type="text/css"
  14. ;;
  15. *)
  16. echo "Unknown format!"
  17. echo
  18. RET=1
  19. continue
  20. ;;
  21. esac
  22. curl --silent \
  23. --header "Content-Type: ${type}; charset=utf-8" \
  24. --data-binary @${fn} \
  25. https://validator.w3.org/nu/?out=text > $OUT
  26. cat $OUT
  27. echo
  28. # We don't fail the check for warnings as some warnings are
  29. # not relevant for us, and we don't currently have a way to
  30. # ignore just those
  31. if grep -q -s -E "^Error:" $OUT; then
  32. RET=1
  33. fi
  34. done
  35. rm $OUT
  36. exit $RET