My public website https://www.chameth.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

minify.sh 816B

1234567891011121314151617181920212223
  1. #!/bin/bash
  2. set -uxeo pipefail
  3. # Compress all the CSS files together
  4. cat /tmp/site/res/css/*.css > "/tmp/css-concatted.css"
  5. yui-compressor "/tmp/css-concatted.css" > "/tmp/css-combined.css"
  6. # Generate a small hash to bust caches if the file changes
  7. HASH=`sha256sum /tmp/css-combined.css | cut -c -10`
  8. # Replace the old CSS with the new
  9. mv "/tmp/css-combined.css" "/tmp/site/res/stylesheet-$HASH.css"
  10. rm -rf "/tmp/site/res/css"
  11. # Replace the references in the HTML, then run tidy over it
  12. for file in $(find /tmp/site/ -name '*.html'); do
  13. sed -i "s#\"/res/css/style.css\"#\"/res/stylesheet-$HASH.css\"#g" "$file"
  14. sed -i '\#"/res/css/.*.css"#d' "$file"
  15. # Tidy exits if there are warnings, which there probably will be...
  16. tidy -q -i -w 120 -m --vertical-space yes --drop-empty-elements no "$file" || true
  17. done