{{- $lazyload := .Page.Site.Params.lazyload -}}
{{- $imageZoom := .Page.Site.Params.imageZoom -}}
{{- $public_cdn := cond .Page.Site.IsServer "" .Page.Site.Params.publicCDN -}}
{{- $Alt := .PlainText | safeHTML -}}
{{- if (urls.Parse (.Destination | safeURL)).Scheme -}}
{{- with $Alt -}}
{{- . | markdownify -}}
{{- end -}}
{{- else -}}
{{- $Image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) -}}
{{- $Permalink := .Destination | relURL | safeURL -}}
{{- $Width := 0 -}}
{{- $Height := 0 -}}
{{- $Srcset := "" -}}
{{- $Srcset_Webp := "" -}}
{{- $Placeholder := "" -}}
{{/* SVG and external images won't work with gallery layout, because their width and height attributes are unknown */}}
{{- $galleryImage := false -}}
{{- if and $Image (not (eq $Image.MediaType.SubType "gif")) -}}
{{- $notSVG := ne (path.Ext .Destination) ".svg" -}}
{{- $Permalink = $Image.RelPermalink -}}
{{- if $notSVG -}}
{{- $Width = $Image.Width -}}
{{- $Height = $Image.Height -}}
{{- $galleryImage = true -}}
{{- if (default true .Page.Site.Params.imageProcessing.content.enabled) -}}
{{- $small := $Image.Resize "640x" -}}
{{- $big := $Image.Resize "1080x" -}}
{{- $small_webp := $Image.Resize "640x webp" -}}
{{- $big_webp := $Image.Resize "1080x webp" -}}
{{- $Placeholder = ($Image.Resize "50x").Filter (images.GaussianBlur 2) -}}
{{- $Srcset = printf `%s 640w, %s 1080w` (print $public_cdn $small.RelPermalink) (print $public_cdn $big.RelPermalink) -}}
{{- $Srcset_Webp = printf `%s 640w, %s 1080w` (print $public_cdn $small_webp.RelPermalink) (print $public_cdn $big_webp.RelPermalink) -}}
{{- $Placeholder = print $public_cdn $Placeholder.RelPermalink -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- if $Image -}}
{{- $Permalink = $Image.RelPermalink -}}
{{- end -}}
{{- end -}}
{{- $Permalink = print $public_cdn $Permalink -}}
{{- with $Srcset_Webp -}}{{- end -}}
{{- if not (eq $Alt .Page.Title) -}}
{{- with $Alt -}}
{{- . | markdownify -}}
{{- end -}}
{{- end -}}
{{- end -}}