figure.html 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. {{/* Enable image to be loaded from local page dir or media library at `static/img/`. */}}
  2. {{ $image_src := .Get "src" }}
  3. {{ if .Get "library" }}
  4. {{ $image_src = printf "img/%s" $image_src | relURL }}
  5. {{ end }}
  6. {{/* Disallow user from opening image in the lightbox? */}}
  7. {{ $lightbox := eq (.Get "lightbox" | default "true") "true" }}
  8. {{/* Get lightbox group for showing multiple images in a lightbox. */}}
  9. {{ $group := .Get "lightbox-group" | default "" }}
  10. {{/* Get caption. Support legacy `title` option. */}}
  11. {{ $caption := .Get "title" | default (.Get "caption") | default "" }}
  12. <figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
  13. {{ if $lightbox }}
  14. <a data-fancybox="{{$group}}" href="{{$image_src}}" {{ with $caption }}data-caption="{{ .|markdownify|emojify }}"{{ end }}>
  15. {{ else if .Get "link"}}
  16. <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{.}}"{{ end }}{{ with .Get "rel" }} rel="{{.}}"{{ end }}>
  17. {{ end -}}
  18. <img src="{{$image_src}}" alt="{{ with .Get "alt" }}{{.}}{{end}}" {{ with .Get "width" }}width="{{.}}" {{end}}{{ with .Get "height" }}height="{{.}}" {{end}}>
  19. {{- if or $lightbox (.Get "link") }}</a>{{ end }}
  20. {{ if $caption }}
  21. {{/* Localize the figure numbering (if enabled). */}}
  22. {{ $figure := split (i18n "figure" | default "Figure %d:") "%d" }}
  23. <figcaption{{ if eq (.Get "numbered") "true" }} data-pre="{{ index $figure 0 }}" data-post="{{ index $figure 1 }}" class="numbered"{{ end }}>
  24. {{ $caption | markdownify | emojify }}
  25. </figcaption>
  26. {{ end }}
  27. </figure>