Skip to content

Commit

Permalink
Update branch_build_hugo_en_alt.yml
Browse files Browse the repository at this point in the history
removed image optimization in favor of offline optimization
  • Loading branch information
simeononsecurity authored Jul 4, 2024
1 parent 5019a37 commit 49daa18
Showing 1 changed file with 0 additions and 120 deletions.
120 changes: 0 additions & 120 deletions .github/workflows/branch_build_hugo_en_alt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ jobs:
hugo-version: "0.122.0"
extended: true

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y imagemagick perl libimage-exiftool-perl jpegoptim optipng gifsicle pngcrush webp
- name: Build Hugo site
uses: actions/cache@v4
with:
Expand All @@ -51,121 +46,6 @@ jobs:
- name: Build Hugo site
run: hugo --cleanDestinationDir -D -E -F --minify --enableGitInfo --cacheDir /tmp/hugo_cache --config /home/runner/work/simeononsecurity.ch/simeononsecurity.ch/config/language/en/config_alt.toml

- name: Optimize images
run: |
MAXIMUM_JPG_SIZE=250
PNG_OPTIMIZATION_LEVEL=2
MAX_WIDTH=1400
NUM_PARALLEL_JOBS=8 # Number of parallel jobs for processing
PUBLIC_DIR="/home/runner/work/simeononsecurity.ch/simeononsecurity.ch/public"
# Function to resize images if wider than MAX_WIDTH
resize_image() {
local image=$1
local width=$(identify -format "%w" "$image")
if [ "$width" -gt "$MAX_WIDTH" ]; then
mogrify -resize "${MAX_WIDTH}>" "$image"
fi
}
export -f resize_image
# Function to remove EXIF data from an image
process_exif() {
local image=$1
exiftool -overwrite_original -all= "$image"
}
export -f process_exif
# Function to optimize JPEG images
optimize_jpeg() {
local image=$1
resize_image "$image"
jpegoptim --strip-all $image
}
export -f optimize_jpeg
# Function to optimize PNG images
optimize_png() {
local image=$1
resize_image "$image"
pngcrush -ow -reduce -brute "$image"
optipng -o$PNG_OPTIMIZATION_LEVEL -clobber -strip all "$image"
}
export -f optimize_png
# Function to optimize GIF images
optimize_gif() {
local image=$1
resize_image "$image"
gifsicle --batch --optimize=3 --colors 256 "$image"
}
export -f optimize_gif
# Function to optimize WebP images
optimize_webp() {
local image=$1
resize_image "$image"
cwebp -q 80 "$image" -o "$image"
}
export -f optimize_webp
# Main script execution
main() {
# Remove EXIF data from JPEG and PNG images
if hash exiftool 2>/dev/null; then
find ${PUBLIC_DIR} -type f -iregex ".*\.\(jpeg\|jpg\|png\)" -print0 | xargs -0 -n1 -P$NUM_PARALLEL_JOBS bash -c 'process_exif "$0"'
else
echo "Install perl-image-exiftool to optimize images"
fi
# Optimize JPEG images
if hash jpegoptim 2>/dev/null; then
find ${PUBLIC_DIR} -type f -iregex ".*\.\(jpeg\|jpg\)" -print0 | xargs -0 -n1 -P$NUM_PARALLEL_JOBS bash -c 'optimize_jpeg "$0"'
else
echo "Install jpegoptim to optimize JPEG images"
fi
# Optimize PNG images
if hash optipng 2>/dev/null && hash pngcrush 2>/dev/null; then
find ${PUBLIC_DIR} -type f -iregex ".*\.\(png\)" -print0 | xargs -0 -n1 -P$NUM_PARALLEL_JOBS bash -c 'optimize_png "$0"'
else
echo "Install optipng and pngcrush to optimize PNG images"
fi
# Optimize GIF images while keeping them animated
if hash gifsicle 2>/dev/null; then
find ${PUBLIC_DIR} -type f -iregex ".*\.\(gif\)" -print0 | xargs -0 -n1 -P$NUM_PARALLEL_JOBS bash -c 'optimize_gif "$0"'
else
echo "Install gifsicle to optimize GIF images"
fi
# Optimize WebP images
if hash cwebp 2>/dev/null; then
find ${PUBLIC_DIR} -type f -iregex ".*\.\(webp\|png\)" -print0 | xargs -0 -n1 -P$NUM_PARALLEL_JOBS bash -c 'optimize_webp "$0"'
else
echo "Install cwebp to optimize WebP images"
fi
# Wait for all background jobs to finish
wait
# Check for errors and exit if any are encountered
if [ $? -ne 0 ]; then
echo "Error encountered during image optimization"
exit 1
else
echo "Image optimization completed successfully"
fi
}
main
- name: Delete non-public folders and files
run: |
find . -mindepth 1 -type d ! -path './public*' ! -path './.git*' ! -path './.github*' -print0 | xargs -0 rm -rf
Expand Down

0 comments on commit 49daa18

Please sign in to comment.