cover.html (3042B)
1 {{- with .cxt}} {{/* Apply proper context from dict */}} 2 {{- if (and .Params.cover.image (not $.isHidden)) }} 3 <figure class="entry-cover"> 4 {{- $loading := cond $.IsSingle "eager" "lazy" }} 5 {{- $addLink := (and site.Params.cover.linkFullImages $.IsSingle) }} 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)) }} 11 {{- $globalResourcesCover := (resources.ByType "image").GetMatch (printf "*%s*" (.Params.cover.image)) }} 12 {{- $cover := (or $pageBundleCover $globalResourcesCover)}} 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 */}} 33 {{- if (and (in $processableFormats $cover.MediaType.SubType) ($responsiveImages) (eq $prod true)) }} 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 }}"> 45 {{- else }}{{/* Unprocessable image or responsive images disabled */}} 46 <img loading="{{ $loading }}" src="{{ $imgdl }}" alt="{{ $alt }}"> 47 {{- end }} 48 {{- else }} 49 {{- /* For absolute urls and external links, no img processing here */}} 50 <img loading="{{ $loading }}" src="{{ $imgdl }}" alt="{{ $alt }}"> 51 {{- end }} 52 53 {{- if $addLink }} 54 </a> 55 {{- end -}} 56 57 {{- /* Display Caption */}} 58 {{- if $.IsSingle }} 59 {{ with .Params.cover.caption -}} 60 <figcaption>{{ . | markdownify }}</figcaption> 61 {{- end }} 62 {{- end }} 63 </figure> 64 {{- end }}{{/* End image */}} 65 {{- end -}}{{/* End context */ -}}