From e049463b3d8659b8019be9455c2bf25c4a235bae Mon Sep 17 00:00:00 2001 From: Thomas <51998416+ThomasBoom89@users.noreply.github.com> Date: Sat, 25 May 2024 10:45:31 +0200 Subject: [PATCH] Render svg images from markdown (#43) * Feature: allow svgs from markdown to be rendered * Feature: add example for render image type svg --- exampleSite/content/post/image-process/index.md | 2 ++ exampleSite/content/post/image-process/index.zh-cn.md | 6 ++++++ layouts/_default/_markup/render-image.html | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/exampleSite/content/post/image-process/index.md b/exampleSite/content/post/image-process/index.md index e6131b3..6520537 100644 --- a/exampleSite/content/post/image-process/index.md +++ b/exampleSite/content/post/image-process/index.md @@ -12,6 +12,8 @@ image = "images/hugo-logo-wide.svg" ![placeholder](https://placeholder.co/1024x768/png "Test for external image") +![svg](./images/hugo-logo-wide.svg "Test for svg") +

diff --git a/exampleSite/content/post/image-process/index.zh-cn.md b/exampleSite/content/post/image-process/index.zh-cn.md index 3ab601c..6b2e8f3 100644 --- a/exampleSite/content/post/image-process/index.zh-cn.md +++ b/exampleSite/content/post/image-process/index.zh-cn.md @@ -11,3 +11,9 @@ image = "images/hugo-logo-wide.svg" ![Photo by Behnam Norouzi on Unsplash](./images/behnam-norouzi-_1ok63FFlM4-unsplash.jpg "Photo by Behnam Norouzi on Unsplash") ![placeholder](https://placeholder.co/1024x768/png "Test for external image") + +![svg](./images/hugo-logo-wide.svg "Test for svg") + +

+ +

diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index ea22ab4..bbd9482 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -12,7 +12,7 @@
-{{- with .Page.Resources.Get $dest -}} +{{- with and (ne (.Page.Resources.Get $dest).MediaType.SubType "svg") (.Page.Resources.Get $dest) -}} {{- $src := . -}} {{- $dataSzes := "(min-width: 1024px) 100vw, 50vw" -}} {{- $actualImg := $src.Resize (print "640x jpg " $filter) -}}