lxndrblz / anatole

Anatole is a minimalistic two-column theme for Hugo.
https://themes.gohugo.io/themes/anatole/
MIT License
650 stars 356 forks source link

Enable webp image encoding #407

Closed Tanddant closed 1 year ago

Tanddant commented 1 year ago

Is your feature request related to a problem? Please describe. I'm trying to keep up my pagespeed score as close to the 100/100 that the theme enables, but I have to consistently convert my images to webp (I use https://squoosh.app/) which is a huge overhead, for something I would love to automate.

Describe the solution you'd like Ideally any images I reference in my posts would automatically be encoded, so I don't have to worry about it, ideally maybe even resize the thumbnail photos for mobile and desktop mode to optimize the page speed score even more!

Describe alternatives you've considered Simply manually encoding the images works fine, it's just extra work

Additional context As far as I can tell from this post it should be relatively easy to implement, but I'm new to Hugo, so I might have missed something obvious

{{ $images := slice }}
{{ $images = $images | append ($img.Resize "300x") }}
{{ if hugo.IsExtended }}
  {{ $images = $images | append ($img.Resize "300x webp") }}
{{ end }}
lxndrblz commented 1 year ago

Unfortunately, this is not really possible in my opinion as the theme does not control how the content is rendered within the post. So far I could see this only being used for the profile picture on the side. However, it wouldn't change much in terms of overall site performance.

Tanddant commented 1 year ago

My main concern is on the frontpage - I accidentally used a 5mb image as cover for a post, which had a huge impact on performance - within posts is another story in itself, I agree the theme shouldn't touch those