figure.html 1.8 KB

1234567891011121314151617181920212223242526272829
  1. <!--
  2. Put this file in /layouts/shortcodes/figure.html
  3. NB this overrides Hugo's built-in "figure" shortcode but is backwards compatible
  4. Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
  5. -->
  6. <!-- count how many times we've called this shortcode; load the css if it's the first time -->
  7. {{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="{{ "css/hugo-easy-gallery.css" | absURL}}" />{{ end }}
  8. {{- $.Page.Scratch.Add "figurecount" 1 -}}
  9. <!-- use either src or link-thumb for thumbnail image -->
  10. {{- $thumb := .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }}
  11. <div class="box{{ with .Get "caption-position" }} fancy-figure caption-position-{{.}}{{end}}{{ with .Get "caption-effect" }} caption-effect-{{.}}{{end}}" {{ with .Get "width" }}style="max-width:{{.}}"{{end}}>
  12. <figure {{ with .Get "class" }}class="{{.}}"{{ end }} itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
  13. <div class="img"{{ if .Parent }} style="background-image: url('{{ print .Site.BaseURL $thumb }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
  14. <img itemprop="thumbnail" src="{{ $thumb }}" {{ with .Get "alt" | default (.Get "caption") | default $thumb }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery -->
  15. </div>
  16. {{ with .Get "link" | default (.Get "src") }}<a href="{{.}}" itemprop="contentUrl"></a>{{ end }}
  17. {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
  18. <figcaption>
  19. {{- with .Get "title" }}<h4>{{.}}</h4>{{ end }}
  20. {{- if or (.Get "caption") (.Get "attr")}}
  21. <p>
  22. {{- .Get "caption" -}}
  23. {{- with .Get "attrlink"}}<a href="{{.}}">{{ .Get "attr" }}</a>{{ else }}{{ .Get "attr"}}{{ end -}}
  24. </p>
  25. {{- end }}
  26. </figcaption>
  27. {{- end }}
  28. </figure>
  29. </div>