Removed thumbnails make target, updated make-thumbs.sh script for portability
This commit is contained in:
5
Makefile
5
Makefile
@@ -44,9 +44,6 @@ version:
|
|||||||
new:
|
new:
|
||||||
$(DOCKER_RUN) ${HUGO_IMAGE} new post/$(shell read -p "Post Name (i.e. my_post.md): " pn; echo $$pn)
|
$(DOCKER_RUN) ${HUGO_IMAGE} new post/$(shell read -p "Post Name (i.e. my_post.md): " pn; echo $$pn)
|
||||||
|
|
||||||
thumbnails:
|
|
||||||
@./make-thumbs.sh
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@# Clean up existing generated site
|
@# Clean up existing generated site
|
||||||
rm -rf public/ resources/
|
rm -rf public/ resources/
|
||||||
@@ -60,5 +57,5 @@ cache:
|
|||||||
@$(DOCKER_RUN) ${AWS_ENV} ${AWS_IMAGE} ${CLOUDFRONT_CMD}
|
@$(DOCKER_RUN) ${AWS_ENV} ${AWS_IMAGE} ${CLOUDFRONT_CMD}
|
||||||
|
|
||||||
# Default target for make (<=3.80)
|
# Default target for make (<=3.80)
|
||||||
.PHONY: static unmount build _run run version new thumbnails clean deploy cache
|
.PHONY: static unmount build _run run version new clean deploy cache
|
||||||
default: build
|
default: build
|
||||||
|
|||||||
@@ -1,26 +1,84 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
|
{ usage="$(cat)"; }<<'EOF'
|
||||||
|
USAGE
|
||||||
|
make-thumbs.sh [OPTIONS] <path>
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
Recursively searches through the passed path, ignoring existing thumbnails,
|
||||||
|
and generates thumbnails for images greater than 600px in width.
|
||||||
|
|
||||||
|
OPTIONS
|
||||||
|
-h, --help Shows this help prompt
|
||||||
|
-d, --dry-run Dry-run that will not create actual thumbnails
|
||||||
|
EOF
|
||||||
|
|
||||||
|
die() {
|
||||||
|
printf '%s\n' "$1" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
printf '%s\n' "$usage"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
while :; do
|
||||||
|
case $1 in
|
||||||
|
-h|-\?|--help)
|
||||||
|
show_help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-d|--dry-run)
|
||||||
|
DRYRUN=1
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
-?*)
|
||||||
|
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ "$1" ]; then
|
||||||
|
BROWSE_PATH=$1
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$BROWSE_PATH" ]; then
|
||||||
|
die 'ERROR: path not specified! (See -h/--help)'
|
||||||
|
fi
|
||||||
|
|
||||||
CONVERT=$(command -v convert)
|
CONVERT=$(command -v convert)
|
||||||
if [ ! $CONVERT ]; then
|
if [ ! "$CONVERT" ]; then
|
||||||
echo "ERROR: imagemagick must be installed!"
|
echo "ERROR: imagemagick must be installed!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for i in $(find static/img/*/ -type f -not -path "*thumb*"); do
|
find "$BROWSE_PATH" -type f -not -path '*thumb*' | while read -r i; do
|
||||||
THUMB_PATH=$(dirname $i)/thumb
|
THUMB_PATH="$(dirname "$i")/thumb"
|
||||||
IMG_NAME=$(basename $i)
|
IMG_NAME="$(basename "$i")"
|
||||||
|
|
||||||
# Generate a thumbnail if the width is greater than 600px
|
# Generate a thumbnail if the width is greater than 600px
|
||||||
if [ $(identify -format "%w" $i) -gt 600 ]; then
|
if [ "$(identify -format "%w" "$i")" -gt 600 ]; then
|
||||||
# Create the thumbnail directory fo the image to be made
|
# Create the thumbnail directory fo the image to be made
|
||||||
if [ ! -d $THUMB_PATH ]; then
|
if [ ! -d "$THUMB_PATH" ]; then
|
||||||
echo "Creating directory $THUMB_PATH..."
|
if [ ! "$DRYRUN" ]; then
|
||||||
mkdir -p $THUMB_PATH
|
mkdir -p "$THUMB_PATH"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create the thumbnail image
|
# Create the thumbnail image
|
||||||
if [ ! -f $THUMB_PATH/$IMG_NAME ]; then
|
if [ ! -f "$THUMB_PATH/$IMG_NAME" ]; then
|
||||||
echo "Converting $IMG_NAME to thumbnail..."
|
printf "└─ Converting %s to thumbnail in %s \n" "$BROWSE_PATH/$IMG_NAME" "$THUMB_PATH"
|
||||||
$CONVERT -resize 600x $i $THUMB_PATH/$IMG_NAME;
|
if [ ! "$DRYRUN" ]; then
|
||||||
|
"$CONVERT" -resize 600x "$i" "$THUMB_PATH/$IMG_NAME";
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user