Gallery shortcode for Hugo. Fork of Li-Wen Yip's Easy Gallery
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

figure.html 1.9KB

123456789101112131415161718192021222324252627282930313233
  1. <!--
  2. SPDX-FileCopyrightText: 2019 Li-Wen Yip <liwen.yip@gmail.com>
  3. SPDX-FileCopyrightText: 2019 Max Mehl <mail@mehl.mx>
  4. SPDX-License-Identifier: MIT
  5. Put this file in /layouts/shortcodes/figure.html
  6. NB this overrides Hugo's built-in "figure" shortcode but is backwards compatible
  7. Documentation and licence at https://github.com/liwenyip/hugo-easy-gallery/
  8. -->
  9. <!-- count how many times we've called this shortcode; load the css if it's the first time -->
  10. {{- if not ($.Page.Scratch.Get "figurecount") }}<link rel="stylesheet" href="/css/snap-gallery.css" />{{ end }}
  11. {{- $.Page.Scratch.Add "figurecount" 1 -}}
  12. <!-- use either src or link-thumb for thumbnail image -->
  13. {{- $thumb := .Get "src" | default (printf "%s." (.Get "thumb") | replace (.Get "link") ".") }}
  14. <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}}>
  15. <figure {{ with .Get "class" }}class="{{.}}"{{ end }} itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject">
  16. <div class="img"{{ if .Parent }} style="background-image: url('{{ $thumb | relURL }}');"{{ end }}{{ with .Get "size" }} data-size="{{.}}"{{ end }}>
  17. <img itemprop="thumbnail" src="{{ $thumb | relURL }}" {{ with .Get "alt" | default (.Get "caption") }}alt="{{.}}"{{ end }}/><!-- <img> hidden if in .gallery -->
  18. </div>
  19. {{ with .Get "link" | default (.Get "src") }}<a href="{{.}}" itemprop="contentUrl"></a>{{ end }}
  20. {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
  21. <figcaption>
  22. {{- with .Get "title" }}<h4>{{.}}</h4>{{ end }}
  23. {{- if or (.Get "caption") (.Get "attr")}}
  24. <p>
  25. {{- .Get "caption" -}}
  26. {{- with .Get "attrlink"}}<a href="{{.}}">{{ .Get "attr" }}</a>{{ else }}{{ .Get "attr"}}{{ end -}}
  27. </p>
  28. {{- end }}
  29. </figcaption>
  30. {{- end }}
  31. </figure>
  32. </div>