From fe59a701586972793ea110b465f65d47b825fb8e Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 16 Jun 2026 18:19:51 +0300 Subject: in0 split album.source.sh into cohesive modules Refactor the ~1442-line album.source.sh ([SRP] violation) into three cohesive modules, leaving album.source.sh a thin coordinator. Pure code move, no behavior change -- whole functions and their doc comments moved verbatim; the assembled bin/shuriken contains the same function set. - image-pipeline.source.sh: ImageMagick derivative generation (create_photo_derivatives, create_all_photo_derivatives) and photo asset prep (prepare_generation_photo_assets). - album-metadata.source.sh: EXIF identify caching, exif tooltip/details helpers, file counts, shuriken.json metadata, EXIF cache clearing and the dry-run plan. - album-render.source.sh: preview/view/details/splash/redirect page rendering, the parallel render-job orchestration and the ALBUM_VIEW_PAGE_BY_PHOTO global. - album.source.sh: thin coordinator (generate, refresh_splash, generate_stats_pages, site-asset/archive/html-clean helpers). Add the three modules to LIB_SOURCES (Justfile) and to the SHURIKEN_LIB_SOURCES markers in src/shuriken.sh, ordered after random and before album.source.sh / stats.source.sh. just build, just test, just shellcheck, just check-generated and git diff --check all pass. Co-Authored-By: Claude Opus 4.8 --- src/lib/image-pipeline.source.sh | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/lib/image-pipeline.source.sh (limited to 'src/lib/image-pipeline.source.sh') diff --git a/src/lib/image-pipeline.source.sh b/src/lib/image-pipeline.source.sh new file mode 100644 index 0000000..876501b --- /dev/null +++ b/src/lib/image-pipeline.source.sh @@ -0,0 +1,84 @@ +create_photo_derivatives() { + local -r photos_dir="$1"; shift + local -r thumbs_dir="$1"; shift + local -r blurs_dir="$1"; shift + local -r photo="$1"; shift + local dirname + local height + + if [[ -f "$DIST_DIR/$thumbs_dir/$photo" \ + && -f "$DIST_DIR/$blurs_dir/$photo" ]]; then + log_verbose "Skipped existing thumb and blur" \ + "$(_display_path "$DIST_DIR/$thumbs_dir/$photo") and" \ + "$(_display_path "$DIST_DIR/$blurs_dir/$photo")" + return + fi + + dirname="$DIST_DIR/$thumbs_dir" + mkdir -p "$dirname" + log_info "Creating thumb $(_display_path "$DIST_DIR/$thumbs_dir/$photo")" + # Double the height, as CSS scales images based on boxing too. + height=$(( THUMBHEIGHT * 2 )) + imagemagick \ + "$DIST_DIR/$photos_dir/$photo" \ + -geometry "x$height" \ + "$DIST_DIR/$thumbs_dir/$photo" + + dirname="$DIST_DIR/$blurs_dir" + mkdir -p "$dirname" + log_info "Creating blur $(_display_path "$DIST_DIR/$blurs_dir/$photo")" + imagemagick \ + "$DIST_DIR/$thumbs_dir/$photo" \ + -flip \ + -blur 0x8 \ + "$DIST_DIR/$blurs_dir/$photo" +} + +create_all_photo_derivatives() { + local -r photos_dir="$1"; shift + local -r thumbs_dir="$1"; shift + local -r blurs_dir="$1"; shift + local -i failed=0 + local -a image_job_pids=() + # Passed by name to wait_for_image_job_slot and wait_for_image_jobs. + # shellcheck disable=SC2034 + local -A image_job_labels=() + # Passed by name to wait_for_image_job_slot and wait_for_image_jobs. + # shellcheck disable=SC2034 + local -A image_job_statuses=() + local photo + + while IFS= read -r photo; do + wait_for_image_job_slot \ + image_job_pids \ + image_job_statuses \ + image_job_labels \ + failed + create_photo_derivatives "$photos_dir" "$thumbs_dir" "$blurs_dir" \ + "$photo" & + image_job_pids+=("$!") + # Read through a nameref in the job-pool helpers. + # shellcheck disable=SC2034 + image_job_labels["$!"]="image derivative job for photo $photo" + done < <( + find "$DIST_DIR/$photos_dir" -maxdepth 1 -type f -printf '%f\n' \ + | sort + ) + + wait_for_image_jobs \ + image_job_pids \ + image_job_statuses \ + image_job_labels \ + failed + if (( failed != 0 )); then + return 1 + fi +} + +prepare_generation_photo_assets() { + warn_unsupported_incoming_files + mkdir -p "$DIST_DIR/photos" + cleanphotos + scalephotos + create_all_photo_derivatives 'photos' 'thumbs' 'blurs' +} -- cgit v1.2.3