2020-10-22 13:12:26 +02:00
|
|
|
{{- with .cxt}} {{/* Apply proper context from dict */}}
|
2020-12-29 12:14:03 +01:00
|
|
|
{{- if (and .Params.cover.image (not $.isHidden)) }}
|
2020-10-22 13:12:26 +02:00
|
|
|
{{- $alt := (.Params.cover.alt | default .Params.cover.caption | plainify) }}
|
|
|
|
<figure class="entry-cover">
|
2021-09-02 17:24:50 +02:00
|
|
|
{{- $responsiveImages := (.Params.cover.responsiveImages | default .Site.Params.cover.responsiveImages) | default true }}
|
2020-10-22 13:12:26 +02:00
|
|
|
{{- $addLink := (and .Site.Params.cover.linkFullImages (not $.IsHome)) }}
|
|
|
|
{{- $cover := (.Page.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }}
|
|
|
|
{{- if $cover -}}{{/* i.e it is present in page bundle */}}
|
2020-11-18 11:15:19 +01:00
|
|
|
{{- if $addLink }}<a href="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" target="_blank"
|
|
|
|
rel="noopener noreferrer">{{ end -}}
|
2020-10-22 13:12:26 +02:00
|
|
|
{{- $sizes := (slice "360" "480" "720" "1080" "1500") }}
|
|
|
|
{{- $processableFormats := (slice "jpg" "jpeg" "png" "tif" "bmp" "gif") }}
|
2020-12-13 15:49:25 +01:00
|
|
|
{{- $prod := (hugo.IsProduction | or (eq .Site.Params.env "production")) }}
|
2021-09-02 17:24:50 +02:00
|
|
|
{{- if (and (in $processableFormats $cover.MediaType.SubType) ($responsiveImages) (eq $prod true)) }}
|
2021-03-27 08:46:10 +01:00
|
|
|
<img loading="lazy" srcset="{{- range $size := $sizes -}}
|
2020-10-22 13:12:26 +02:00
|
|
|
{{- if (ge $cover.Width $size) -}}
|
2020-11-29 05:09:57 +01:00
|
|
|
{{ printf "%s %s" (($cover.Resize (printf "%sx" $size)).Permalink) (printf "%sw ," $size) -}}
|
2020-10-22 13:12:26 +02:00
|
|
|
{{ end }}
|
2021-08-22 08:15:28 +02:00
|
|
|
{{- end -}}{{$cover.Permalink }} {{printf "%dw" ($cover.Width)}}"
|
|
|
|
sizes="(min-width: 768px) 720px, 100vw" src="{{ $cover.Permalink }}" alt="{{ $alt }}"
|
|
|
|
width="{{ $cover.Width }}" height="{{ $cover.Height }}">
|
2020-10-22 13:12:26 +02:00
|
|
|
{{- else }}{{/* Unprocessable image or responsive images disabled */}}
|
2021-03-27 08:46:10 +01:00
|
|
|
<img loading="lazy" src="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" alt="{{ $alt }}">
|
2020-10-22 13:12:26 +02:00
|
|
|
{{- end }}
|
|
|
|
{{- else }}{{/* For absolute urls and external links, no img processing here */}}
|
2020-11-18 11:15:19 +01:00
|
|
|
{{- if $addLink }}<a href="{{ (.Params.cover.image) | absURL }}" target="_blank"
|
|
|
|
rel="noopener noreferrer">{{ end -}}
|
2021-03-27 08:46:10 +01:00
|
|
|
<img loading="lazy" src="{{ (.Params.cover.image) | absURL }}" alt="{{ $alt }}">
|
2020-10-22 13:12:26 +02:00
|
|
|
{{- end }}
|
|
|
|
{{- if $addLink }}</a>{{ end -}}
|
|
|
|
{{/* Display Caption */}}
|
|
|
|
{{- if not $.IsHome }}
|
|
|
|
{{ with .Params.cover.caption }}<p>{{ . | markdownify }}</p>{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
</figure>
|
|
|
|
{{- end }}{{/* End image */}}
|
2021-03-30 14:37:36 +02:00
|
|
|
{{- end -}}{{/* End context */ -}}
|