Fix crash on missing hero

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-09-13 23:23:17 +00:00
parent 8834c6dc21
commit d9a3c4b4a1
2 changed files with 37 additions and 33 deletions

View File

@@ -3,13 +3,15 @@
{{ partial "components/meta/index.html" . }} {{ partial "components/meta/index.html" . }}
{{ $hero := partial "components/hero/process.html" .Params.hero }} {{ $hero := partial "components/hero/process.html" .Params.hero }}
{{ $data := partial "components/image/process.html" (dict "page" .Page "src" $hero.src) }} {{ if $hero.src }}
{{ $data := partial "components/image/process.html" (dict "page" .Page "src" $hero.src) }}
{{ $final := merge $data $hero }} {{ $final := merge $data $hero }}
{{ if $hero.exif }} {{ if $hero.exif }}
{{ $caption := partial "components/image/exif.html" $data.original }} {{ $caption := partial "components/image/exif.html" $data.original }}
{{ $final = merge $final (dict "caption" $caption) }} {{ $final = merge $final (dict "caption" $caption) }}
{{ end }}
{{ partial "components/image/index.html" $final }}
{{ end }} {{ end }}
{{ partial "components/image/index.html" $final }}
</section> </section>

View File

@@ -3,37 +3,39 @@
{{ range sort .Pages "Date" "desc" }} {{ range sort .Pages "Date" "desc" }}
{{ if not .Params.private }} {{ if not .Params.private }}
{{ $hero := partial "components/hero/process.html" .Params.hero }} {{ $hero := partial "components/hero/process.html" .Params.hero }}
{{ $data := partial "components/image/process.html" (dict "page" . "src" $hero.src) }} {{ if $hero.src }}
{{ $data := partial "components/image/process.html" (dict "page" . "src" $hero.src) }}
{{- $caption := .Title -}} {{- $caption := .Title -}}
{{- $title := $hero.title | default $caption | plainify -}} {{- $title := $hero.title | default $caption | plainify -}}
{{- $alt := $hero.alt | default $title | plainify -}} {{- $alt := $hero.alt | default $title | plainify -}}
<div class="image grid-item"> <div class="image grid-item">
<a <a
href="{{- .RelPermalink -}}" href="{{- .RelPermalink -}}"
data-pswp-src="{{- $data.full.RelPermalink -}}" data-pswp-src="{{- $data.full.RelPermalink -}}"
data-pswp-width="{{- $data.full.Width -}}" data-pswp-width="{{- $data.full.Width -}}"
data-pswp-height="{{- $data.full.Height -}}" data-pswp-height="{{- $data.full.Height -}}"
class="pswp-image" class="pswp-image"
> >
<img <img
src="{{- $data.thumb.RelPermalink -}}" src="{{- $data.thumb.RelPermalink -}}"
width="{{- $data.thumb.Width -}}" width="{{- $data.thumb.Width -}}"
height="{{- $data.thumb.Height -}}" height="{{- $data.thumb.Height -}}"
loading="lazy" loading="lazy"
{{ with $title }}title="{{- . -}}"{{ end }} {{ with $title }}title="{{- . -}}"{{ end }}
{{ with $alt }}alt="{{- . -}}"{{ end }} {{ with $alt }}alt="{{- . -}}"{{ end }}
/> />
</a> </a>
<div class="pswp-caption-content"> <div class="pswp-caption-content">
<div> <div>
<a href="{{- .RelPermalink -}}">{{ $caption }}</a> <a href="{{- .RelPermalink -}}">{{ $caption }}</a>
{{ partial "components/meta/index.html" . }} {{ partial "components/meta/index.html" . }}
</div>
</div> </div>
</div> </div>
</div> {{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}
</div> </div>