reduce_index.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #/bin/sh
  2. # Processing script to optionally reduce filesystem use by miniying, gzipping and preparing index.htm for embedding in code.
  3. # Please see readme.md for more information.
  4. # Requires xdd which is part of the VIM package
  5. # Requires npm
  6. # sudo apt install npm
  7. # ln -s /usr/bin/nodejs /usr/bin/node
  8. # Requires html-minifier
  9. # sudo npm install html-minifier -g
  10. html-minifier \
  11. --case-sensitive \
  12. --collapse-boolean-attributes \
  13. --collapse-whitespace \
  14. --minify-css true \
  15. --minify-js true \
  16. --process-conditional-comments \
  17. --remove-attribute-quotes \
  18. --remove-comments \
  19. --remove-empty-attributes \
  20. --remove-optional-tags \
  21. --remove-redundant-attributes \
  22. --remove-script-type-attributes \
  23. --remove-style-link-type-attributes \
  24. -o index.htm \
  25. ../data/edit/index.htm
  26. if [ $? -ne 0 ]
  27. then
  28. echo "Error minifying index.htm"
  29. exit -1
  30. fi
  31. if [ -e index.htm.gz ]
  32. then
  33. rm index.htm.gz
  34. fi
  35. gzip index.htm
  36. if [ $? -ne 0 ]
  37. then
  38. echo "Error gzipping minified index.htm"
  39. exit -1
  40. fi
  41. echo '// WARNING: Auto-generated file. Please do not modify by hand.' > index_htm.h
  42. echo '// This file is an embeddable version of the gzipped index.htm file.' >> index_htm.h
  43. echo '// To update it, please rerun the `reduce_index.sh` script located in the `extras` subfolder' >> index_htm.h
  44. echo '// then recompile the sketch after each change to the `index.html` file.' >> index_htm.h
  45. xxd -i index.htm.gz >> index_htm.h
  46. if [ $? -ne 0 ]
  47. then
  48. echo "Error creating include file from index.htm.gz"
  49. exit -1
  50. fi
  51. echo Reduce complete.