picture.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <picture{{ with .wrapperClass }} class="{{ . }}"{{ end }}>
  2. {{- range .sources }}
  3. <source srcset="{{ .srcset }}" type="{{ .type }}" />
  4. {{- end }}
  5. {{- $attrs := slice
  6. (printf `class="%s"` .className)
  7. (printf `src="%s"` .src)
  8. (printf `alt="%s"` .alt)
  9. }}
  10. {{- with .caption }}
  11. {{- $attrs = $attrs | append (printf `title="%s"` .) }}
  12. {{- end }}
  13. {{- if .lazyLoading }}
  14. {{- $attrs = $attrs | append `loading="lazy"` }}
  15. {{- end }}
  16. {{- with .naturalHeight }}
  17. {{- $attrs = $attrs | append (printf `height="%s"` (string .)) }}
  18. {{- end }}
  19. {{- with .naturalWidth }}
  20. {{- $attrs = $attrs | append (printf `width="%s"` (string .)) }}
  21. {{- end }}
  22. {{- with .style }}
  23. {{- $attrs = $attrs | append (printf `style="%s"` (delimit . `; `)) }}
  24. {{- end }}
  25. {{- if .original }}
  26. {{- with .originalSrc }}
  27. {{- $attrs = $attrs | append (printf `data-src="%s"` .) }}
  28. {{- end }}
  29. {{- with .originalWidth }}
  30. {{- $attrs = $attrs | append (printf `data-width="%s"` (string .)) }}
  31. {{- end }}
  32. {{- with .originalHeight }}
  33. {{- $attrs = $attrs | append (printf `data-height="%s"` (string .)) }}
  34. {{- end }}
  35. {{- end }}
  36. <img {{ delimit $attrs " " | safeHTMLAttr }} />
  37. </picture>