mfg92/hugo-shortcode-gallery

Add support for SVG

Opened this issue · 2 comments

Hi there,

here is the error I get when I add a SVG file in the images folder:

ERROR 2021/04/18 23:19:30 Rebuild failed:

ERROR 2021/04/18 23:19:30 "[...]/hugo/img/content/gallery/index.md:23:1": failed to render shortcode "gallery": failed to process shortcode: "[...]/hugo/img/themes/hugo-shortcode-gallery/layouts/shortcodes/gallery.html:89:30": execute of template failed: template: shortcodes/gallery.html:89:30: executing "shortcodes/gallery.html" at <$original.Fit>: error calling Fit: *resources.genericResource is not an image

Thanks a lot for this awesome module!

mfg92 commented

Hi @iaeiou,
here are my thoughts about adding support for SVG:

  • http://miromannino.github.io/Justified-Gallery/ (which is used by hugo-shortcode-gallery) supports SVG only since the latest version. However that version has some kind of bug (I can not remember what it was) which prevented me to upgrade.
  • I do not know if Swipebox (another dependency of this shortcode) supports SVG.
  • I does not looks like it is possible for hugo to convert SVGs to PNGs. If that would work it would allow an easy workaround.
  • Currently I get the width and height of an image from hugo and add these as attributes of the image to HTML. These attributes are used by Justified-Gallery for layouting. But this would not be possible for SVGs as hugo does not understand them.

So it seems to me that adding SVG support is hard work, as that means the latest version of Justified Gallery has to be integrated into this project and potentially support for SVG has to be added to Swipebox (which is sadly not maintained any more). Furthermore some other special treatments of SVG would be needed, for instance you can not simple created a blurred thumbnail of a SVG.

So what i am trying to say is that adding SVG support is not a small task and possibly not even possible right now.
Perhaps I miss something...
PR are of course always welcome.