forked from Sync/hugo-theme-stack
There's now a threshold for each scenario. Images less than x width will not be processed.
39 lines
1.9 KiB
HTML
39 lines
1.9 KiB
HTML
<header class="article-header">
|
|
{{- $image := partialCached "helper/image" (dict "Context" . "Type" "article") .RelPermalink "article" -}}
|
|
{{ if $image.exists }}
|
|
<div class="article-image">
|
|
<a href="{{ .RelPermalink }}">
|
|
{{ if $image.resource }}
|
|
{{- $Permalink := $image.resource.RelPermalink -}}
|
|
{{- $Width := $image.resource.Width -}}
|
|
{{- $Height := $image.resource.Height -}}
|
|
{{- $Srcset := slice -}}
|
|
|
|
{{- if .Page.Site.Params.ImageProcessing.Cover.Enabled -}}
|
|
{{- $keys := slice "small" "big" -}}
|
|
{{- range $keys -}}
|
|
{{- with (index $.Page.Site.Params.ImageProcessing.Cover .) -}}
|
|
{{- if gt $Width .Threshold -}}
|
|
{{- $resized := $image.resource.Resize (printf "%dx" .Width) -}}
|
|
{{- $Srcset = $Srcset | append (printf `%s %dw` $resized.RelPermalink .Width) -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- $Srcset = $Srcset | append (printf `%s %dw` $Permalink $Width) -}}
|
|
{{- end -}}
|
|
|
|
<img src="{{ $Permalink }}"
|
|
{{ with $Srcset }}srcset="{{ delimit . `, ` }}"{{ end }}
|
|
width="{{ $Width }}"
|
|
height="{{ $Height }}"
|
|
loading="lazy"
|
|
alt="Featured image of post {{ .Title }}" />
|
|
{{ else }}
|
|
<img src="{{ $image.permalink }}" loading="lazy" alt="Featured image of post {{ .Title }}" />
|
|
{{ end }}
|
|
</a>
|
|
</div>
|
|
{{ end }}
|
|
|
|
{{ partialCached "article/components/details" . .RelPermalink }}
|
|
</header> |