From 35e36b7a89d10d6a39ebbd28c4c89827d9de283c Mon Sep 17 00:00:00 2001 From: stereobooster Date: Wed, 4 Oct 2023 02:50:08 +0200 Subject: [PATCH] add sizes to SVG --- layouts/partials/picture.html | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/layouts/partials/picture.html b/layouts/partials/picture.html index 207f5d07..98a10a47 100644 --- a/layouts/partials/picture.html +++ b/layouts/partials/picture.html @@ -40,13 +40,33 @@ type="image/webp" /> {{ end }} + {{ $width := ""}} + {{ $height := ""}} + {{ if eq .MediaType.SubType "svg" }} + {{ $svgContent := $resource.Content }} + {{ range (findRESubmatch `width=["']?(\d*)` $svgContent 1) }} + {{ $width = index . 1 }} + {{ end }} + {{ range (findRESubmatch `height=["']?(\d*)` $svgContent 1) }} + {{ $height = index . 1 }} + {{ end }} + {{ if (eq "" $width $height) }} + {{ range (findRESubmatch `viewBox=["']?(\d*) (\d*) (\d*) (\d*)` $svgContent 1) }} + {{ $width = index . 3 }} + {{ $height = index . 4 }} + {{ end }} + {{ end }} + {{ else }} + {{ $width = .Width }} + {{ $height = .Height }} + {{ end}}