{{ $img := .img }} {{ $alt := .alt }} {{ $class := .class }} {{ $lazy := .lazy }} {{ $webp := .webp }} {{ $lqip := .lqip }} {{ $x2 := .x2 | default false }} {{ 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 }} {{ $width := .Width }} {{ $height := .Height }} {{ if $x2 }} {{ $width = div .Width 2 }} {{ $height = div .Height 2 }} {{ end }} {{ if $webp }} {{ end }} {{ . }} {{ end }} {{ end }}