~jcc/hugo-site

2351d4b61046b19c4f561ecfe357e80f38840934 — Jason Cox 6 months ago 3bb806f
Use normal filenames for compressed images
1 files changed, 5 insertions(+), 2 deletions(-)

M layouts/shortcodes/picture.html
M layouts/shortcodes/picture.html => layouts/shortcodes/picture.html +5 -2
@@ 1,5 1,8 @@
{{ $p := .Page.Resources.Get (.Get "src") }}
<!-- hack to get decent filenames: https://discourse.gohugo.io/t/change-file-name-for-resized-image-resources/14219/8 -->
{{ $webp := slice ($p.Process "webp") | resources.Concat (replaceRE "\\.[^.]+$" ".webp" $p.RelPermalink) }}
{{ $jpeg := slice ($p.Process "jpeg") | resources.Concat (replaceRE "\\.[^.]+$" ".jpg" $p.RelPermalink) }}
<picture>
  <source srcset="{{ ($p.Process "webp").RelPermalink }}" type="image/webp" />
  <img src="{{ ($p.Process "jpg").RelPermalink }}" alt="{{ .Get "alt" }}" {{ with .Get "width" }} width="{{ . }}" {{ end }} />
  <source srcset="{{ $webp.RelPermalink }}" type="image/webp" />
  <img src="{{ $jpeg.RelPermalink }}" alt="{{ .Get "alt" }}" {{ with .Get "width" }} width="{{ . }}" {{ end }} />
</picture>