|
1 | 1 | {{- with .cxt}} {{/* Apply proper context from dict */}}
|
2 | 2 | {{- if (and .Params.cover.image (not $.isHidden)) }}
|
3 |
| -{{- $alt := (.Params.cover.alt | default .Params.cover.caption | plainify) }} |
4 |
| -{{- $loading := cond $.IsSingle "eager" "lazy" }} |
5 | 3 | <figure class="entry-cover">
|
6 |
| - {{- $responsiveImages := (.Params.cover.responsiveImages | default site.Params.cover.responsiveImages) | default true }} |
| 4 | + {{- $loading := cond $.IsSingle "eager" "lazy" }} |
7 | 5 | {{- $addLink := (and site.Params.cover.linkFullImages $.IsSingle) }}
|
8 |
| - {{- $pageBundleCover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }} |
| 6 | + {{- $prod := (hugo.IsProduction | or (eq site.Params.env "production")) }} |
| 7 | + {{- $alt := (.Params.cover.alt | default .Params.cover.caption | plainify) }} |
| 8 | + {{- $responsiveImages := (.Params.cover.responsiveImages | default site.Params.cover.responsiveImages) | default true }} |
| 9 | + |
| 10 | + {{- $pageBundleCover := (.Resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }} |
9 | 11 | {{- $globalResourcesCover := (resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }}
|
10 | 12 | {{- $cover := (or $pageBundleCover $globalResourcesCover)}}
|
11 |
| - {{- if $cover -}}{{/* i.e it is present in page bundle */}} |
12 |
| - {{- if $addLink }}<a href="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" target="_blank" |
13 |
| - rel="noopener noreferrer">{{ end -}} |
14 |
| - {{- $sizes := (slice "360" "480" "720" "1080" "1500") }} |
15 |
| - {{- $processableFormats := (slice "jpg" "jpeg" "png" "tif" "bmp" "gif") -}} |
16 |
| - {{- if hugo.IsExtended -}} |
17 |
| - {{- $processableFormats = $processableFormats | append "webp" -}} |
18 |
| - {{- end -}} |
19 |
| - {{- $prod := (hugo.IsProduction | or (eq site.Params.env "production")) }} |
| 13 | + {{- /* We are not using the .Param.cover.relative to decide the location of image */}} |
| 14 | + {{- /* If we have the image in pageBundle or globalResources we can process the image */}} |
| 15 | + |
| 16 | + {{- $sizes := (slice "360" "480" "720" "1080" "1500") }} |
| 17 | + {{- $processableFormats := (slice "jpg" "jpeg" "png" "tif" "bmp" "gif") -}} |
| 18 | + {{- if hugo.IsExtended -}} |
| 19 | + {{- $processableFormats = $processableFormats | append "webp" -}} |
| 20 | + {{- end -}} |
| 21 | + |
| 22 | + {{- $imgdl := (.Params.cover.image) | absURL }} |
| 23 | + {{- if $cover -}} |
| 24 | + {{- $imgdl = $cover.Permalink }} |
| 25 | + {{- end -}} |
| 26 | + |
| 27 | + {{- if $addLink }} |
| 28 | + <a href="{{ $imgdl }}" target="_blank" rel="noopener noreferrer"> |
| 29 | + {{- end }} |
| 30 | + |
| 31 | + {{- if $cover -}} |
| 32 | + {{/* i.e it is present in page bundle */}} |
20 | 33 | {{- if (and (in $processableFormats $cover.MediaType.SubType) ($responsiveImages) (eq $prod true)) }}
|
21 |
| - <img loading="{{$loading}}" srcset="{{- range $size := $sizes -}} |
22 |
| - {{- if (ge $cover.Width $size) -}} |
23 |
| - {{ printf "%s %s" (($cover.Resize (printf "%sx" $size)).Permalink) (printf "%sw ," $size) -}} |
24 |
| - {{ end }} |
25 |
| - {{- end -}}{{$cover.Permalink }} {{printf "%dw" ($cover.Width)}}" |
26 |
| - sizes="(min-width: 768px) 720px, 100vw" src="{{ $cover.Permalink }}" alt="{{ $alt }}" |
27 |
| - width="{{ $cover.Width }}" height="{{ $cover.Height }}"> |
| 34 | + <img loading="{{$loading}}" |
| 35 | + srcset='{{- range $size := $sizes -}} |
| 36 | + {{- if (ge $cover.Width $size) }} |
| 37 | + {{- printf "%s %s" (($cover.Resize (printf "%sx" $size)).Permalink) (printf "%sw," $size) }} |
| 38 | + {{- end }} |
| 39 | + {{- end }} |
| 40 | + {{- printf "%s %dw" ($cover.Permalink) ($cover.Width) }}' |
| 41 | + src="{{ $cover.Permalink }}" |
| 42 | + sizes="(min-width: 768px) 720px, 100vw" |
| 43 | + width="{{ $cover.Width }}" height="{{ $cover.Height }}" |
| 44 | + alt="{{ $alt }}"> |
28 | 45 | {{- else }}{{/* Unprocessable image or responsive images disabled */}}
|
29 |
| - <img loading="{{$loading}}" src="{{ (path.Join .RelPermalink .Params.cover.image) | absURL }}" alt="{{ $alt }}"> |
| 46 | + <img loading="{{ $loading }}" src="{{ $imgdl }}" alt="{{ $alt }}"> |
30 | 47 | {{- end }}
|
31 |
| - {{- else }}{{/* For absolute urls and external links, no img processing here */}} |
32 |
| - {{- if $addLink }}<a href="{{ (.Params.cover.image) | absURL }}" target="_blank" |
33 |
| - rel="noopener noreferrer">{{ end -}} |
34 |
| - <img loading="{{$loading}}" src="{{ (.Params.cover.image) | absURL }}" alt="{{ $alt }}"> |
| 48 | + {{- else }} |
| 49 | + {{- /* For absolute urls and external links, no img processing here */}} |
| 50 | + <img loading="{{ $loading }}" src="{{ $imgdl }}" alt="{{ $alt }}"> |
35 | 51 | {{- end }}
|
36 |
| - {{- if $addLink }}</a>{{ end -}} |
37 |
| - {{/* Display Caption */}} |
| 52 | + |
| 53 | + {{- if $addLink }} |
| 54 | + </a> |
| 55 | + {{- end -}} |
| 56 | + |
| 57 | + {{- /* Display Caption */}} |
38 | 58 | {{- if $.IsSingle }}
|
39 |
| - {{ with .Params.cover.caption }}<p>{{ . | markdownify }}</p>{{- end }} |
| 59 | + {{ with .Params.cover.caption -}} |
| 60 | + <figcaption>{{ . | markdownify }}</figcaption> |
| 61 | + {{- end }} |
40 | 62 | {{- end }}
|
41 | 63 | </figure>
|
42 | 64 | {{- end }}{{/* End image */}}
|
|
0 commit comments