{{/* - Change viewport sizes, lazy-loading,async & width,alt,link,caption in the shortcode call - Hardcode sizes in this file - If an image should not be resized or changed - e.g. because it is low quality - simply dont put it in the page bundle but in /static Example call: {{
}} figure with auto-resizing, webp-conversion and srcset v2021-06-27 Drop-in replacement for Hugo's figure shortcode as of 2020-05-02 that uses the picture tag, img srcset and webp format to enable browsers to download only the resolution that they need. The resizing and srcset magic only works for images that are part of the page bundle. It will fall back to stock Hugo figure behaviour otherwise. Changes by @georgeblck: - 2021-06-27 Added picture-tag and optional lazy loading, async and viewport changing - 2021-06-05 Added webp (only works when hugo version >= 0.83.0) and lazy loading Changes and initial release by @cpbotha: - 2020-05-10 fall back to stock Hugo behaviour when no page bundle found - 2020-05-04 no unnecessary resizes, sizes in array - 2020-05-02 initial release - original srcset img shortcode from: https://laurakalbag.com/processing-responsive-images-with-hugo/ - original hugo figure shortcode from: https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/shortcodes/figure.html - no unnecessary resizes and more nudges by Stéfan van der Walt https://mentat.za.net/ - mashing together and srcset logic fixes by Charl P. Botha https://cpbotha.net/ */}} {{/* hugo will resize to all of these sizes that are smaller than your original. configure if you like! */}} {{ $sizes := (slice "480" "800" "1200" "1500") }} {{/* get file that matches the filename as specified as src="" in shortcode */}} {{ $src := .Page.Resources.GetMatch (printf "*%s*" (.Get "src")) }} {{- if .Get "link" -}} {{- end }} {{ if $src }} {{ end }} {{ with .Get {{ if $src }} {{ end }} {{- if .Get "link" }} {{ end -}} {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
{{ with (.Get "title") -}}

{{ . }}

{{- end -}} {{- if or (.Get "caption") (.Get "attr") -}}

{{- .Get "caption" | markdownify -}} {{- with .Get "attrlink" }} {{- end -}} {{- .Get "attr" | markdownify -}} {{- if .Get "attrlink" }}{{ end }}

{{- end }}
{{- end }}