Last active
January 9, 2022 20:31
-
-
Save xlfe/8051348 to your computer and use it in GitHub Desktop.
Deploy a jekyll site to a s3 bucket including gzip compression of html/js/css files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment