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" . }}
{{ $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 }}
{{ if $hero.exif }}
{{ $caption := partial "components/image/exif.html" $data.original }}
{{ $final = merge $final (dict "caption" $caption) }}
{{ $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 }}
{{ end }}
{{ partial "components/image/index.html" $final }}
</section>

View File

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