Deploy a jekyll site to a s3 bucket including gzip compression of html/js/css files

Felix Barbalet
2013-12-20T07:02:27Z

_deploy.sh

| #!/bin/bash -x
|
| # Deploy a jekyll site to a s3 bucket with gzip compression of html/js/css files
| #
| # To use - place in your root directory of your jekyll
| # site, and edit the BUCKET="<YOUR_S3_BUCKET>" variable at the top
| # to reflect the S3 bucket you're uploading to.
| #
| # You will need to have jekyll, and s3cmd already setup
| # (and it relies upon standard *nix utilities like find,
| # egrep, xargs and gzip)
|
| BUCKET="pv.tl"
|
| #remove old site
| rm -rf ./_site/
|
| #generate site
| jekyll build
|
| #compress html/css/js files (-n removes the timestamp)
| find _site | egrep "\.(html|js|css)$" | xargs -I{} gzip -n -9 {}
|
| #remove the .gz extension
| find _site | egrep "\.(html|js|css)\.gz$" | xargs -I{} bash -c 'FILE="{}"; mv ${FILE} ${FILE%.*}'
|
| #upload non-compressed files
| s3cmd -P sync --no-preserve --exclude '*.html' --exclude '*.css' --exclude '*.js' _site/ s3://$BUCKET/
|
| #upload compressed files
| s3cmd -P sync --no-preserve --exclude '*.*' --add-header='Content-Encoding: gzip' --include '*.html' --include '*.css' --include '*.js' _site/ s3://$BUCKET/
|
| #remove removed files
| s3cmd -P sync --delete-removed _site/ s3://$BUCKET/