diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-16 18:19:51 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-16 18:19:51 +0300 |
| commit | fe59a701586972793ea110b465f65d47b825fb8e (patch) | |
| tree | 87ca3f64b695a0a8fa63d578be1aa4937bb59e01 /src/lib/image-pipeline.source.sh | |
| parent | cd7cf797bc633700c5ee7e986077f366c000f0b9 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'src/lib/image-pipeline.source.sh')
| -rw-r--r-- | src/lib/image-pipeline.source.sh | 84 |
1 files changed, 84 insertions, 0 deletions
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' +} |
