2020-10-22 07:12:26 -04:00
|
|
|
{{- with .cxt}} {{/* Apply proper context from dict */}}
|
2020-12-29 06:14:03 -05:00
|
|
|
{{- if (and .Params.cover.image (not $.isHidden)) }}
|
2020-10-22 07:12:26 -04:00
|
|
|
{{- $alt := (.Params.cover.alt | default .Params.cover.caption | plainify) }}
|
2023-12-16 02:39:19 -05:00
|
|
|
{{- $loading := cond $.IsSingle "eager" "lazy" }}
|
2020-10-22 07:12:26 -04:00
|
|
|
<figure class="entry-cover">
|
2022-03-27 09:14:06 -04:00
|
|
|
{{- $responsiveImages := (.Params.cover.responsiveImages | default site.Params.cover.responsiveImages) | default true }}
|
2023-12-16 02:39:19 -05:00
|
|
|
{{- $addLink := (and site.Params.cover.linkFullImages $.IsSingle) }}
|
2023-04-28 10:43:57 -04:00
|
|
|
{{- $pageBundleCover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }}
|
|
|
|
{{- $globalResourcesCover := (resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }}
|
|
|
|
{{- $cover := (or $pageBundleCover $globalResourcesCover)}}
|
2020-10-22 07:12:26 -04:00
|
|
|
{{- if $cover -}}{{/* i.e it is present in page bundle */}}
|
2020-11-18 05:15:19 -05:00
|
|
|
{{- if $addLink }}<a href="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" target="_blank"
|
|
|
|
rel="noopener noreferrer">{{ end -}}
|
2020-10-22 07:12:26 -04:00
|
|
|
{{- $sizes := (slice "360" "480" "720" "1080" "1500") }}
|
2021-10-22 10:29:36 -04:00
|
|
|
{{- $processableFormats := (slice "jpg" "jpeg" "png" "tif" "bmp" "gif") -}}
|
|
|
|
{{- if hugo.IsExtended -}}
|
|
|
|
{{- $processableFormats = $processableFormats | append "webp" -}}
|
|
|
|
{{- end -}}
|
2022-03-27 09:14:06 -04:00
|
|
|
{{- $prod := (hugo.IsProduction | or (eq site.Params.env "production")) }}
|
2021-09-02 11:24:50 -04:00
|
|
|
{{- if (and (in $processableFormats $cover.MediaType.SubType) ($responsiveImages) (eq $prod true)) }}
|
2023-12-16 02:39:19 -05:00
|
|
|
<img loading="{{$loading}}" srcset="{{- range $size := $sizes -}}
|
2020-10-22 07:12:26 -04:00
|
|
|
{{- if (ge $cover.Width $size) -}}
|
2020-11-28 23:09:57 -05:00
|
|
|
{{ printf "%s %s" (($cover.Resize (printf "%sx" $size)).Permalink) (printf "%sw ," $size) -}}
|
2020-10-22 07:12:26 -04:00
|
|
|
{{ end }}
|
2021-08-22 02:15:28 -04: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 07:12:26 -04:00
|
|
|
{{- else }}{{/* Unprocessable image or responsive images disabled */}}
|
2023-12-16 02:39:19 -05:00
|
|
|
<img loading="{{$loading}}" src="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" alt="{{ $alt }}">
|
2020-10-22 07:12:26 -04:00
|
|
|
{{- end }}
|
|
|
|
{{- else }}{{/* For absolute urls and external links, no img processing here */}}
|
2020-11-18 05:15:19 -05:00
|
|
|
{{- if $addLink }}<a href="{{ (.Params.cover.image) | absURL }}" target="_blank"
|
|
|
|
rel="noopener noreferrer">{{ end -}}
|
2023-12-16 02:39:19 -05:00
|
|
|
<img loading="{{$loading}}" src="{{ (.Params.cover.image) | absURL }}" alt="{{ $alt }}">
|
2020-10-22 07:12:26 -04:00
|
|
|
{{- end }}
|
|
|
|
{{- if $addLink }}</a>{{ end -}}
|
|
|
|
{{/* Display Caption */}}
|
2023-12-16 02:39:19 -05:00
|
|
|
{{- if $.IsSingle }}
|
2020-10-22 07:12:26 -04:00
|
|
|
{{ with .Params.cover.caption }}<p>{{ . | markdownify }}</p>{{- end }}
|
|
|
|
{{- end }}
|
|
|
|
</figure>
|
|
|
|
{{- end }}{{/* End image */}}
|
2021-03-30 08:37:36 -04:00
|
|
|
{{- end -}}{{/* End context */ -}}
|