{{- /* responsive-image.html — safe image renderer. Resize/Fit only work on raster resources (png/jpg/webp/gif). This partial: - resizes + builds srcset for raster Hugo resources, - falls back to a plain for SVG resources or static paths, - falls back to a CSS gradient placeholder when nothing resolves. A missing image can therefore NEVER break the build. Call with a dict. Provide ONE of: resource : a Hugo resource (assets/ or page bundle), OR src : a string path (e.g. "/images/logo.svg") Optional: alt, class, loading ("lazy"|"eager"), sizes, widths (slice of ints). */ -}} {{- $r := .resource -}} {{- $src := .src -}} {{- $alt := .alt | default "" -}} {{- $class := .class | default "" -}} {{- $loading := .loading | default "lazy" -}} {{- $sizes := .sizes | default "100vw" -}} {{- $widths := .widths | default (slice 400 800 1200) -}} {{- if $r -}} {{- $sub := $r.MediaType.SubType -}} {{- if in (slice "png" "jpg" "jpeg" "webp" "gif") $sub -}} {{- $ow := $r.Width -}} {{- $srcset := slice -}} {{- range $widths -}} {{- if le . $ow -}} {{- $img := $r.Resize (printf "%dx" .) -}} {{- $srcset = $srcset | append (printf "%s %dw" $img.RelPermalink $img.Width) -}} {{- end -}} {{- end -}} {{- $fallback := $r -}} {{- if gt $ow 1200 -}}{{- $fallback = $r.Resize "1200x" -}}{{- end -}} {{ $alt }} {{- else -}} {{ $alt }} {{- end -}} {{- else if $src -}} {{ $alt }} {{- else -}} {{- end -}}