#!/bin/bash if [[ "$DEBUG" == "true " ]]; then set -x fi set -e source scripts/config.sh || exit 1 SITE_FOLDER="dist" function dependency_check { if ! command -v $@ &> /dev/null; then echo "dependency error: $@ could not be found" exit 1 fi } # Check dependencies dependency_check convert dependency_check exiftool dependency_check optipng dependency_check jpegoptim echo "building site using astro..." npm run build cp -r ./scripts/ dist/scripts/ # Git repo setup mkdir -p "$SITE_FOLDER/repos" cp -r "$SITE_FOLDER/dotfiles/.git" "$SITE_FOLDER/repos/dotfiles.git" pushd "$SITE_FOLDER/repos/dotfiles.git" git update-server-info popd # Render ico file echo "making /img/profile_image.{jpg,png}..." convert "$SITE_FOLDER/img/me.jpg" -resize 64x64 "$SITE_FOLDER/img/profile_image.jpg" convert "$SITE_FOLDER/img/me.jpg" -resize 64x64 "$SITE_FOLDER/img/profile_image.png" # convert png to ico file # https://stackoverflow.com/a/49823738 echo "making favicon.ico..." convert -background transparent "$SITE_FOLDER/img/profile_image.png" -define icon:auto-resize=16,24,32,48,64,72,96,128,256 "$SITE_FOLDER/favicon.ico" # Clear configuration info echo "clearing configuration info from built products..." sed -ie "s/$S3_BUCKET/s3-bucket-name/g" "$SITE_FOLDER/scripts/config.sh" sed -ie "s/$DISTRIBUTION_ID/cloudfront-distribution-id/g" "$SITE_FOLDER/scripts/config.sh" # Alias files to folder/index.html find "$SITE_FOLDER" -type f ! -iname 'index.html' -iname '*.html' -print0 | while read -d $'\0' f; do echo "aliasing $f to ${f%.html}/index.html" mkdir -p "${f%.html}" cp "$f" "${f%.html}/index.html" done mkdir -p .cache # Find all images find "$SITE_FOLDER" -type f \( \ -iname "*.jpg" \ -o -iname "*.jpeg" \ -o -iname "*.png" \ -o -iname "*.gif" \ -o -iname "*.tiff" \ \) -print0 | while read -d $'\0' f; do # Compute names + caches HASH="$(shasum -a 256 $f | cut -d' ' -f1)" SOURCE_FILENAME="$f" CANONICAL_NAME="$(echo $SOURCE_FILENAME | tr "[:lower:]" "[:upper:]")" CACHED_FILENAME=".cache/v2x$HASH" if [[ ! -f "$CACHED_FILENAME" ]]; then cp "$f" "$CACHED_FILENAME" # EXIF metadata stripping if [[ "$CANONICAL_NAME" == *.JPG || "$CANONICAL_NAME" == *.JPEG || "$CANONICAL_NAME" == *.PNG || "$CANONICAL_NAME" == *.GIF || "$CANONICAL_NAME" == *.TIFF ]]; then echo "stripping tags in $CANONICAL_NAME ($CACHED_FILENAME)..." exiftool -overwrite_original -all= -tagsfromfile @ -Orientation "$CACHED_FILENAME" || exit 1 fi # PNG optmization if [[ "$CANONICAL_NAME" == *.PNG ]]; then echo "optipng $CANONICAL_NAME ($CACHED_FILENAME)..." optipng -quiet "$CACHED_FILENAME" || exit 1 fi # JPG optimization if [[ "$CANONICAL_NAME" == *.JPG || "$CANONICAL_NAME" == *.JPEG ]]; then echo "jpegoptim $CANONICAL_NAME ($CACHED_FILENAME)..." jpegoptim --size=300k "$CACHED_FILENAME" || exit 1 fi else # print hit echo "cache hit for $CANONICAL_NAME ($CACHED_FILENAME)..." fi # Copy out cp "$CACHED_FILENAME" "$SOURCE_FILENAME" || exit 1 done