{{ $img := .img }} {{ $alt := .alt }} {{ $class := .class }} {{ $lazy := .lazy }} {{ $webp := .webp }} {{ $lqip := .lqip }} {{ with $img }} {{ if (eq .MediaType.SubType "svg") }} {{ $width := ""}} {{ $height := ""}} {{ $svgContent := .Content }} {{ range (findRESubmatch `]*width=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }} {{ $width = index . 1 }} {{ end }} {{ range (findRESubmatch `]*height=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }} {{ $height = index . 1 }} {{ end }} {{ if (eq "" $width $height) }} {{ range (findRESubmatch `]*viewBox=["']?([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*)` $svgContent 1) }} {{ $width = index . 3 }} {{ $height = index . 4 }} {{ end }} {{ end }} {{ if (eq "" $width $height) }} {{ warnf "Can't detect width and height for SVG %s" .RelPermalink }} {{/* do not use lazy without dimensions */}} {{ $lazy = false }} {{ end }} {{ . }} {{ else }} {{ if $webp }} {{ end }} {{ . }} {{ end }} {{ end }}