diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-12 23:47:33 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-12 23:47:33 +0300 |
| commit | 052b4aec6ef252f8cb5e5e114a09645073be9ff3 (patch) | |
| tree | 685b21d29157f3ef0f19efdef0f4338926d82967 | |
| parent | 09720e2cf95d04a8650da12b27fb8cc6c6c80113 (diff) | |
Refactor EXIF tooltip parsing for em0
| -rwxr-xr-x | bin/shuriken | 49 | ||||
| -rw-r--r-- | src/lib/album.source.sh | 49 | ||||
| -rwxr-xr-x | tests/cli.sh | 2 |
3 files changed, 70 insertions, 30 deletions
diff --git a/bin/shuriken b/bin/shuriken index ff6173f..5a0bab2 100755 --- a/bin/shuriken +++ b/bin/shuriken @@ -1560,30 +1560,38 @@ _first_exif_value_to() { done } -photo_exif_tooltip_text() { +_photo_exif_values_to() { + local -n output_ref="$1"; shift local -r photo="$1"; shift local -r photo_path="$1"; shift + local line + + output_ref=() + while IFS= read -r line; do + if [[ "$line" =~ ^[[:space:]]*exif:([^:]+):[[:space:]]*(.*)$ ]]; then + # output_ref writes to the caller-provided associative array. + # shellcheck disable=SC2034 + output_ref["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}" + fi + done < <(cached_photo_identify_output "$photo" "$photo_path") +} + +_photo_exif_tooltip_text_from_values() { + local -r exif_name="$1"; shift + local -n values_ref="$exif_name" local aperture local camera local date_time local iso local key - local line local make local model local separator='' local shutter_speed - local -A exif_values=() local -a tooltip_parts=() - while IFS= read -r line; do - if [[ "$line" =~ ^[[:space:]]*exif:([^:]+):[[:space:]]*(.*)$ ]]; then - exif_values["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}" - fi - done < <(cached_photo_identify_output "$photo" "$photo_path") - - make="${exif_values[Make]:-}" - model="${exif_values[Model]:-}" + make="${values_ref[Make]:-}" + model="${values_ref[Model]:-}" camera="$make" if [ -n "$model" ]; then if [ -n "$make" ]; then @@ -1600,12 +1608,12 @@ photo_exif_tooltip_text() { fi fi - _first_exif_value_to aperture exif_values FNumber ApertureValue - _first_exif_value_to iso exif_values \ + _first_exif_value_to aperture "$exif_name" FNumber ApertureValue + _first_exif_value_to iso "$exif_name" \ ISOSpeedRatings PhotographicSensitivity ISO - _first_exif_value_to shutter_speed exif_values \ + _first_exif_value_to shutter_speed "$exif_name" \ ExposureTime ShutterSpeedValue - _first_exif_value_to date_time exif_values \ + _first_exif_value_to date_time "$exif_name" \ DateTimeOriginal DateTimeDigitized DateTime if [ -n "$camera" ]; then @@ -1633,6 +1641,17 @@ photo_exif_tooltip_text() { fi } +photo_exif_tooltip_text() { + local -r photo="$1"; shift + local -r photo_path="$1"; shift + # exif_values is populated and read through nameref helpers. + # shellcheck disable=SC2034 + local -A exif_values=() + + _photo_exif_values_to exif_values "$photo" "$photo_path" + _photo_exif_tooltip_text_from_values exif_values +} + render_details_page() { local -r html_dir="$1"; shift local -r photos_dir="$1"; shift diff --git a/src/lib/album.source.sh b/src/lib/album.source.sh index b5495f5..00fd327 100644 --- a/src/lib/album.source.sh +++ b/src/lib/album.source.sh @@ -217,30 +217,38 @@ _first_exif_value_to() { done } -photo_exif_tooltip_text() { +_photo_exif_values_to() { + local -n output_ref="$1"; shift local -r photo="$1"; shift local -r photo_path="$1"; shift + local line + + output_ref=() + while IFS= read -r line; do + if [[ "$line" =~ ^[[:space:]]*exif:([^:]+):[[:space:]]*(.*)$ ]]; then + # output_ref writes to the caller-provided associative array. + # shellcheck disable=SC2034 + output_ref["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}" + fi + done < <(cached_photo_identify_output "$photo" "$photo_path") +} + +_photo_exif_tooltip_text_from_values() { + local -r exif_name="$1"; shift + local -n values_ref="$exif_name" local aperture local camera local date_time local iso local key - local line local make local model local separator='' local shutter_speed - local -A exif_values=() local -a tooltip_parts=() - while IFS= read -r line; do - if [[ "$line" =~ ^[[:space:]]*exif:([^:]+):[[:space:]]*(.*)$ ]]; then - exif_values["${BASH_REMATCH[1]}"]="${BASH_REMATCH[2]}" - fi - done < <(cached_photo_identify_output "$photo" "$photo_path") - - make="${exif_values[Make]:-}" - model="${exif_values[Model]:-}" + make="${values_ref[Make]:-}" + model="${values_ref[Model]:-}" camera="$make" if [ -n "$model" ]; then if [ -n "$make" ]; then @@ -257,12 +265,12 @@ photo_exif_tooltip_text() { fi fi - _first_exif_value_to aperture exif_values FNumber ApertureValue - _first_exif_value_to iso exif_values \ + _first_exif_value_to aperture "$exif_name" FNumber ApertureValue + _first_exif_value_to iso "$exif_name" \ ISOSpeedRatings PhotographicSensitivity ISO - _first_exif_value_to shutter_speed exif_values \ + _first_exif_value_to shutter_speed "$exif_name" \ ExposureTime ShutterSpeedValue - _first_exif_value_to date_time exif_values \ + _first_exif_value_to date_time "$exif_name" \ DateTimeOriginal DateTimeDigitized DateTime if [ -n "$camera" ]; then @@ -290,6 +298,17 @@ photo_exif_tooltip_text() { fi } +photo_exif_tooltip_text() { + local -r photo="$1"; shift + local -r photo_path="$1"; shift + # exif_values is populated and read through nameref helpers. + # shellcheck disable=SC2034 + local -A exif_values=() + + _photo_exif_values_to exif_values "$photo" "$photo_path" + _photo_exif_tooltip_text_from_values exif_values +} + render_details_page() { local -r html_dir="$1"; shift local -r photos_dir="$1"; shift diff --git a/tests/cli.sh b/tests/cli.sh index 62cede8..1e66ec8 100755 --- a/tests/cli.sh +++ b/tests/cli.sh @@ -2594,6 +2594,7 @@ test_integration_generates_album_outputs_and_cleans() { "$details_html" test::assert_not_contains 'class="details-photo-link" href="1-2.html"' \ "$details_html" + test::assert_not_contains ' title=' "$details_html" test::assert_contains '<title>Integration album</title>' "$top_index_html" test::assert_contains \ '<link rel="icon" href="./favicon.ico" type="image/x-icon">' \ @@ -4138,6 +4139,7 @@ test_generate_renders_exif_details() { test::assert_contains '<td>1/125</td>' "$details_html" test::assert_not_contains 'geometry: 120x90' "$details_html" test::assert_not_contains 'Model & "X"' "$details_html" + test::assert_not_contains 'title=""' "$details_html" test::assert_not_contains 'No EXIF details available.' "$details_html" test::teardown |
