Skip to content

Instantly share code, notes, and snippets.

@ilokhov
Created April 2, 2018 20:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilokhov/4ec1cdce9a86a404aa7df332df0f5065 to your computer and use it in GitHub Desktop.
Save ilokhov/4ec1cdce9a86a404aa7df332df0f5065 to your computer and use it in GitHub Desktop.
Build shell script for personal website
#!/bin/bash
# clean dist directory and copy all files from src
rm -rf dist && mkdir dist
cp -a src/. dist/
### images
# declare sizes
declare -a sizes=('710' '1000' '1420')
# loop over images
for image in dist/img/*; do
# loop over sizes
for size in "${sizes[@]}"; do
# define new filenames
fnamelength=${#image}
outputimage=${image:0:(fnamelength-4)}-${size}${image:(fnamelength-4):fnamelength}
# create new files
cp $image $outputimage
# resize
sips $outputimage -Z $size
done
# delete original image
rm $image
done
# optimise images (if argument -d [development] is not present)
if [[ $1 != '-d' && '$1' != '' ]]; then
mkdir dist/imgmin
imagemin dist/img/* --out-dir=dist/imgmin
rm -rf dist/img && mkdir dist/img
cp -a dist/imgmin/. dist/img
rm -rf dist/imgmin
fi
### autoprefixer
postcss --use autoprefixer -r dist/css/style.css
### minify css
cleancss -o dist/css/style.min.css dist/css/style.css
timestamp=$(date +%s)
mv dist/css/style.min.css dist/css/$timestamp.style.min.css
replace 'css/style.css' 'css/'$timestamp'.style.min.css' dist/index.html
replace 'css/style.css' 'css/'$timestamp'.style.min.css' dist/404.html
rm dist/css/style.css
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment