{{- $src := (.Destination | safeURL) -}}
{{- $src = replace $src "./" "" -}}
{{- $fragments := (split $src "#") -}}
{{- $src = index $fragments 0 -}}
{{- $imgwidth := .Page.Store.Get "imgwidth" | default 1200 -}}
{{- $isFeatured := eq (.Page.Store.Get "featuredClass") "cover" -}}
{{ with $.Title }}{{ end }}
{{- with (or ((.Page.Resources.ByType "image").Get $src) ((resources.ByType "image").Get $src)) -}}
{{- if strings.HasSuffix $src ".svg" -}}
{{ .Content | safeHTML }}
{{- else -}}
{{- /* Two-size responsive pipeline: a narrow variant for mobile,
a wide variant at the configured imgwidth for desktop + HiDPI.
GIFs skip resizing (golang/go#53364). */ -}}
{{- $isRaster := and (ne .MediaType.SubType "gif") (not (strings.HasSuffix $src ".svg")) -}}
{{- $format := cond hugo.IsExtended " webp" "" -}}
{{- $narrowW := 800 -}}
{{- if ge $imgwidth 1200 -}}{{ $narrowW = 800 }}{{- else -}}{{ $narrowW = div $imgwidth 2 }}{{- end -}}
{{- $wide := . -}}
{{- $narrow := "" -}}
{{- if and $isRaster (gt .Width $imgwidth) -}}
{{- $wide = .Resize (printf "%dx%s" $imgwidth $format) -}}
{{- end -}}
{{- if and $isRaster (gt .Width $narrowW) -}}
{{- $narrow = .Resize (printf "%dx%s" $narrowW $format) -}}
{{- end -}}
{{- if and (not hugo.IsExtended) (gt .Width $imgwidth) -}}
{{ warnf "Hugo Extended not detected; render-image.html is serving unconverted raster images." }}
{{- end -}}
{{- /* Opaque JPEGs get a tiny base64 placeholder as background */ -}}
{{- $placeholder := "" -}}
{{- if or (eq .MediaType.SubType "jpg") (eq .MediaType.SubType "jpeg") -}}
{{- $placeholder = .Resize "48x q20 jpg Gaussian" -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- end -}}
{{ with $.Title }}{{ . | markdownify }}{{ end }}