Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion assets/sass/teaser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
}

.m-teaser__image img {
aspect-ratio: 16/9;
border-radius: var(--border-radius-l) var(--border-radius-l) 0 0;
object-fit: cover;
height: 100%;
Expand Down
61 changes: 36 additions & 25 deletions layouts/partials/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,41 @@
{{- $name := $image.RelPermalink | strings.TrimSuffix (printf ".%s" $image.MediaType.SubType) -}}
{{- $extension := $image.MediaType.SubType -}}

<picture>
{{- $widths := slice -}}
{{- if gt $image.Width 500 -}}
{{- $widths = $widths | append 500 -}}
{{- end -}}
{{- if gt $image.Width 800 -}}
{{- $widths = $widths | append 800 -}}
{{- end -}}
{{- if gt $image.Width 1200 -}}
{{- $widths = $widths | append 1200 -}}
{{- end -}}
{{- if gt $image.Width 1500 -}}
{{- $widths = $widths | append 1500 -}}
{{- end -}}
{{- if gt $image.Width 2200 -}}
{{- $widths = $widths | append 2200 -}}
{{- end -}}
{{- $widths := slice -}}
{{- if gt $image.Width 500 -}}
{{- $widths = $widths | append 500 -}}
{{- end -}}
{{- if gt $image.Width 800 -}}
{{- $widths = $widths | append 800 -}}
{{- end -}}
{{- if gt $image.Width 1200 -}}
{{- $widths = $widths | append 1200 -}}
{{- end -}}
{{- if gt $image.Width 1500 -}}
{{- $widths = $widths | append 1500 -}}
{{- end -}}
{{- if gt $image.Width 2200 -}}
{{- $widths = $widths | append 2200 -}}
{{- end -}}

{{- $srcset := slice -}}
{{- range $i, $width := $widths -}}
{{- with $image.Resize (printf "%dx" $width) | resources.Copy (print $name "_" $width "." $extension) -}}
{{- $srcset = $srcset | append (printf "%s %dw" .RelPermalink $width) -}}
{{- end -}}
{{- $srcset := slice -}}
{{- range $i, $width := $widths -}}
{{- with $image.Resize (printf "%dx" $width) | resources.Copy (print $name "_" $width "." $extension) -}}
{{- $srcset = $srcset | append (printf "%s %dw" .RelPermalink $width) -}}
{{- end -}}
{{- $srcset = $srcset | append (printf "%s %dw" $image.RelPermalink $image.Width) -}}
{{- printf "<img src=\"%s\" alt=\"\" loading=\"%s\" srcset=\"%s\" sizes=\"(max-width: 576px) calc(100vw - 3.2rem), (max-width: 768px) 540px, (max-width: 992px) 720px, (max-width: 1200px) 960px, (max-width: 1400px) 1140px, 1320px\">" $image.RelPermalink $loading (delimit $srcset ", ") | safeHTML -}}
</picture>
{{- end -}}
{{- $srcset = $srcset | append (printf "%s %dw" $image.RelPermalink $image.Width) -}}

{{- $styles := "" -}}
{{- if and $image.Width -}}
{{- $styles = printf "aspect-ratio: %d / %d" $image.Width $image.Height -}}
{{- end -}}

<img
src="{{ $image.RelPermalink }}"
alt=""
loading="{{ $loading }}"
srcset="{{ delimit $srcset ", " }}"
sizes="(max-width: 576px) calc(100vw - 3.2rem), (max-width: 768px) 540px, (max-width: 992px) 720px, (max-width: 1200px) 960px, (max-width: 1400px) 1140px, 1320px"
style="{{ $styles | safeCSS }}"
>
Loading