figure.html 1.6 KB

1234567891011121314151617181920212223242526272829
  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. {{ $lightbox := eq (.Get "lightbox" | default "true") "true" }}
  7. {{ $group := .Get "lightbox-group" | default "" }}
  8. <figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
  9. {{ if $lightbox }}
  10. <a data-fancybox="{{$group}}" href="{{$image_src}}" {{ with .Get "caption"}}data-caption="{{ .|markdownify|emojify }}"{{ end }}>
  11. {{ else if .Get "link"}}
  12. <a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{.}}"{{ end }}{{ with .Get "rel" }} rel="{{.}}"{{ end }}>
  13. {{ end }}
  14. <img src="{{$image_src}}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }}{{ with .Get "height" }}height="{{.}}" {{ end }}>
  15. {{ if or $lightbox (.Get "link") }}</a>{{ end }}
  16. {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
  17. {{ $figure := split (i18n "figure" | default "Figure %d:") "%d" }}
  18. <figcaption data-pre="{{ index $figure 0 }}" data-post="{{ index $figure 1 }}" {{ if eq (.Get "numbered") "true" }}class="numbered"{{ end }}>
  19. {{ if isset .Params "title" }}<h4>{{ .Get "title" | markdownify | emojify }}</h4>{{ end }}
  20. {{ if or (.Get "caption") (.Get "attr")}}<p>
  21. {{ .Get "caption" | markdownify | emojify }}
  22. {{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
  23. {{ .Get "attr" }}
  24. {{ if .Get "attrlink"}}</a> {{ end }}
  25. </p> {{ end }}
  26. </figcaption>
  27. {{ end }}
  28. </figure>