From 14a7988db385a58b52efbb8eb0f7a326df568fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Fri, 18 Nov 2022 16:45:20 +0100 Subject: [PATCH] theme: fix build errors when referencing SVGs in markdown #393 --- exampleSite/content/tests/images/_index.en.md | 12 ++++++++++-- exampleSite/content/tests/images/test.svg | 7 +++++++ layouts/partials/shortcodes/image.html | 6 ++++-- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 exampleSite/content/tests/images/test.svg diff --git a/exampleSite/content/tests/images/_index.en.md b/exampleSite/content/tests/images/_index.en.md index de0d3ee1e2..db8287bcab 100644 --- a/exampleSite/content/tests/images/_index.en.md +++ b/exampleSite/content/tests/images/_index.en.md @@ -7,6 +7,10 @@ Some testing for different styles of image links. ## Markdown +### Resource SVG + +![Magic](test.svg?classes=shadow) + ### Relative to page ![Magic](magic.gif?classes=shadow) @@ -15,7 +19,7 @@ Some testing for different styles of image links. ![Magic](../images/magic.gif?classes=shadow&height=50px) -### Static +### Static SVG ![Logo](/images/logo.svg?classes=shadow&height=50px) @@ -33,6 +37,10 @@ Some testing for different styles of image links. ## HTML +### Resource SVG + +

+ ### Relative to page

@@ -41,7 +49,7 @@ Some testing for different styles of image links.

-### Static +### Static SVG

diff --git a/exampleSite/content/tests/images/test.svg b/exampleSite/content/tests/images/test.svg new file mode 100644 index 0000000000..48b180dc69 --- /dev/null +++ b/exampleSite/content/tests/images/test.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/layouts/partials/shortcodes/image.html b/layouts/partials/shortcodes/image.html index bfefc0bd7f..81fc264709 100644 --- a/layouts/partials/shortcodes/image.html +++ b/layouts/partials/shortcodes/image.html @@ -20,8 +20,10 @@ {{- if $dest_url.RawQuery }} {{- $url = printf "%s?%s" $url $dest_url.RawQuery }} {{- end }} - {{- $height = printf "%dpx" $image.Height }} - {{- $width = printf "%dpx" $image.Width }} + {{- if ne $image.MediaType.SubType "svg" }} + {{- $height = printf "%dpx" $image.Height }} + {{- $width = printf "%dpx" $image.Width }} + {{- end }} {{- end }} {{- if $dest_url.RawQuery }} {{- $classes = (replaceRE "\\s+" " " (replaceRE "," " " ($dest_url.Query.Get "classes") ) ) }}