mfg92 / hugo-shortcode-gallery

A theme component with a gallery shortcode for the static site generator hugo.
MIT License
354 stars 66 forks source link

showExif displays placeholder text even if tag does not exist. #37

Closed carstenstann closed 2 years ago

carstenstann commented 2 years ago

Thanks for the amazing shortcode! It's exactly what I was attempting to build for my site, but better. I found a small bug and have a suggestion below.


Inside of the gallery.html the following snippet controls the display image exif data. The problem is that placeholder text such as the 'mm', 'f/', 'sec', and 'ISO' either preceding or following their respective tags is displayed regardless of whether the tag itself is available in the metadata or not. This problem only occurs if showExif=true and no metadata is available for a given image.

{{ if $showExif }}
    data-description="{{ .Model }} + {{ .LensModel }}<br/>{{ .FocalLength }}mm f/{{ .FNumber }} {{ .ExposureTime }}sec ISO {{ .ISOSpeedRatings }}"
{{ end }}

This results in the following exif display, for images w/o available metadata ('QSS-32_32' is from the description):

image

A simple solution is to wrap each tag's lookup inside a with statement:

{{ if $showExif }}
    data-description="{{with .Model}}{{ . }}{{end}}{{with .LensModel}} {{ . }}{{end}}<br/>{{with .FocalLength}} {{ . }}mm{{end}}{{with .FNumber}} f/{{ . }}{{ end }}{{with .ExposureTime}} {{ . }}sec{{end}}{{with .ISOSpeedRatings }} ISO {{ . }}{{end}}"
{{ end }}

Wrapping tag lookups inside with statements only displays them if they are available, which results in the following display of the same image above (again note that 'QSS-32_32' is from the description):

image
mfg92 commented 2 years ago

Thank you @carstenstann for your detailed bug report and the suggested solution. I modified your solution a tiny bit. Is your issue solved with the latest version?

carstenstann commented 2 years ago

Hi @mfg92, 2be808e solved the issue on my end. Thanks for implementing the fix!