hugo-theme-stack/layouts/partials/article/components/header.html

39 lines
1.9 KiB
HTML
Raw Normal View History

<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>