From 6353c33ae2c7417705fdbdff3ae836ad81af8a29 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Sat, 13 Sep 2025 22:32:16 +0000 Subject: [PATCH] Add exif hero images Signed-off-by: Nikolaos Karaolidis --- assets/sass/image.scss | 2 +- layouts/_default/_markup/render-image.html | 2 +- layouts/_shortcodes/exif-image.html | 25 +++++++++++++++++++ layouts/partials/components/hero/index.html | 9 ++++++- layouts/partials/components/hero/process.html | 10 +++++--- layouts/partials/components/image/exif.html | 22 ++++++++++++++++ .../partials/components/image/process.html | 2 +- 7 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 layouts/_shortcodes/exif-image.html create mode 100644 layouts/partials/components/image/exif.html diff --git a/assets/sass/image.scss b/assets/sass/image.scss index 2f797f7..ab7b0d5 100644 --- a/assets/sass/image.scss +++ b/assets/sass/image.scss @@ -10,7 +10,7 @@ img { figcaption { text-align: center; - padding-top: 0.5rem; + padding-top: 1rem; color: color-mix(in srgb, var(--text) 50%, var(--background)); } } diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 9aecd77..9ecdb09 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,3 +1,3 @@ {{ $data := partial "components/image/process.html" (dict "page" .Page "src" .Destination) }} -{{ partial "components/image/index.html" (merge $data (dict "caption" .Text "alt" .Title)) }} +{{ partial "components/image/index.html" (merge $data (dict "caption" .Text "title" .Title)) }} {{- /* chomp trailing newline */ -}} diff --git a/layouts/_shortcodes/exif-image.html b/layouts/_shortcodes/exif-image.html new file mode 100644 index 0000000..c2d509e --- /dev/null +++ b/layouts/_shortcodes/exif-image.html @@ -0,0 +1,25 @@ +{{ $src := "" }} +{{ if .IsNamedParams }} + {{ $src = .Get "src" }} +{{ else }} + {{ $src = .Get 0 }} +{{ end }} + +{{ $title := "" }} +{{ if .IsNamedParams }} + {{ $title = .Get "title" }} +{{ else }} + {{ $title = .Get 1 }} +{{ end }} + +{{ $alt := "" }} +{{ if .IsNamedParams }} + {{ $alt = .Get "alt" }} +{{ else }} + {{ $alt = .Get 1 }} +{{ end }} + +{{ $data := partial "components/image/process.html" (dict "page" .Page "src" $src) }} +{{ $caption := partial "components/image/exif.html" $data.original }} +{{ partial "components/image/index.html" (merge $data (dict "caption" $caption "title" $title "alt" $alt)) }} +{{- /* chomp trailing newline */ -}} diff --git a/layouts/partials/components/hero/index.html b/layouts/partials/components/hero/index.html index 28f47f8..a933baf 100644 --- a/layouts/partials/components/hero/index.html +++ b/layouts/partials/components/hero/index.html @@ -4,5 +4,12 @@ {{ $hero := partial "components/hero/process.html" .Params.hero }} {{ $data := partial "components/image/process.html" (dict "page" .Page "src" $hero.src) }} - {{ partial "components/image/index.html" (merge $data $hero) }} + + {{ $final := merge $data $hero }} + {{ if $hero.exif }} + {{ $caption := partial "components/image/exif.html" $data.original }} + {{ $final = merge $final (dict "caption" $caption) }} + {{ end }} + + {{ partial "components/image/index.html" $final }} diff --git a/layouts/partials/components/hero/process.html b/layouts/partials/components/hero/process.html index d25da28..8fb8fb3 100644 --- a/layouts/partials/components/hero/process.html +++ b/layouts/partials/components/hero/process.html @@ -2,14 +2,16 @@ {{- $caption := "" -}} {{- $title := "" -}} {{- $alt := "" -}} +{{- $exif := false -}} {{- if reflect.IsMap . -}} {{- $src = .src -}} - {{- $caption = .caption | default "" -}} - {{- $title = .title | default $caption | plainify -}} - {{- $alt = .alt | default $title | plainify -}} + {{- $caption = .caption -}} + {{- $title = .title -}} + {{- $alt = .alt -}} + {{- $exif = .exif | default false -}} {{- else -}} {{- $src = . -}} {{- end -}} -{{- return (dict "src" $src "caption" $caption "title" $title "alt" $alt) -}} +{{- return dict "src" $src "caption" $caption "title" $title "alt" $alt "exif" $exif -}} diff --git a/layouts/partials/components/image/exif.html b/layouts/partials/components/image/exif.html new file mode 100644 index 0000000..2470eb5 --- /dev/null +++ b/layouts/partials/components/image/exif.html @@ -0,0 +1,22 @@ +{{ $exif := .Exif.Tags }} + +{{ $make := $exif.Make }} +{{ $model := $exif.Model }} + +{{ $lensMake := $exif.LensMake }} +{{ $lensModel := $exif.LensModel }} + +{{ $lens := "" }} +{{ if ne $make $lensMake }} + {{ $lens = printf "%s %s" $lensMake $lensModel }} +{{ else }} + {{ $lens = $lensModel }} +{{ end }} + +{{ $focal := printf "%.1f" (float $exif.FocalLength) }} +{{ $focal35 := printf "%.1f" (float $exif.FocalLengthIn35mmFormat) }} +{{ $shutter := printf "%d" $exif.ExposureTime }} +{{ $aperture := printf "%d" $exif.FNumber }} +{{ $iso := printf "%d" $exif.ISO }} + +{{ return printf "%s %s, %s @ %s mm (%s mm), %s s, f/%s, ISO %s" $make $model $lens $focal $focal35 $shutter $aperture $iso }} diff --git a/layouts/partials/components/image/process.html b/layouts/partials/components/image/process.html index 70bb8c2..298f572 100644 --- a/layouts/partials/components/image/process.html +++ b/layouts/partials/components/image/process.html @@ -20,4 +20,4 @@ {{- $thumb = $original | images.Filter (images.Process "webp q75") -}} {{- end -}} -{{- return (dict "original" $original "full" $full "thumb" $thumb) -}} +{{- return dict "original" $original "full" $full "thumb" $thumb -}}