Instantly share code, notes, and snippets.

Embed
What would you like to do?
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