Hello Javier, I write to you directly because you seem to have a similar challenge or goal that I have. I hope you have already solved what you were trying to do. I spent quite a while finding the way to bulk conversion in bash from jpg to webp to figure out later that Safari does not support the latest format. I would like to have the two alternatives (*.jpg, *.webp) to let the browser choose.
My idea will be in the markdown of each post, theoretically something like this.
date = 2017-02-10
title = “BlaBla”
featured_image = “/images/01.webp”, “/images/01.jpg”
But I have tried some alternatives without success.
Do you or anyone in the community interested in the topic have any idea or how to achieve this?
You can put webp images in /static – but not in /assets. Images there have special meaning in Hugo: We can resize, add filters etc. But there is not native (encoder) support for webp in Go yet.
Thanks for your reply @bep I actually have the images in /static and everything went smoothly running the site locally. I mean I have already the images in two formats.
My problem was to realise that Safari does not support the webp extension. Therefore I was thinking of an alternative to have this formats form users of browsers that support the *.webp format, but also have the *.jpg backup for Safari users.
I don’t know if there is a way of via markdown of having two featured images to achieve an alternative image source when the html is generated.
Like
[quote=“bep, post:5, topic:21278”]
Search for render hooks in the documentation.
[/quote] I will. Thank you very much for your support and all the great work you do!
If your still interrested, I made a shortcode file: webp_img.html in the layout/shortcodes directory.
I hope this will help. It has been tested on the Chrome/Brave, Firefox, IE11, Edge and Safari.
Amazing, thank you very much! Just over a few weeks late! I just did THIS EXACT same snippet by myself a few weeks ago, forgot to share it (my bad).
Guys, if you are reading this, espirit90 got it right. This works flawless, though I have to use “if server” with mine because sometimes hugo tends not to read the webp images (for some reason). I have a node js converter I ran before deploying my site that makes every large image into an alternative .webp version (which ties nicely with this script, which I only use for large images)