figure.html 1.3 KB

12345678910111213141516171819202122
  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. <figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
  7. {{ if .Get "link"}}<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>{{ end }}
  8. <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 }}/>
  9. {{ if .Get "link"}}</a>{{ end }}
  10. {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
  11. {{ $figure := split (i18n "figure" | default "Figure %d:") "%d" }}
  12. <figcaption data-pre="{{ index $figure 0 }}" data-post="{{ index $figure 1 }}" {{ if eq (.Get "numbered") "true" }}class="numbered"{{ end }}>
  13. {{ if isset .Params "title" }}<h4>{{ .Get "title" | markdownify | emojify }}</h4>{{ end }}
  14. {{ if or (.Get "caption") (.Get "attr")}}<p>
  15. {{ .Get "caption" | markdownify | emojify }}
  16. {{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
  17. {{ .Get "attr" }}
  18. {{ if .Get "attrlink"}}</a> {{ end }}
  19. </p> {{ end }}
  20. </figcaption>
  21. {{ end }}
  22. </figure>