hugo-theme-hyde-hyde/layouts/shortcodes/fig.html

46 lines
1.6 KiB
HTML
Raw Normal View History

{{ $fig := newScratch }}
{{ if .Get "caption" }}
{{ $fig.Set "caption" (.Get "caption") }}
{{ else if .Get "alt" }}
{{ $fig.Set "caption" (.Get "alt") }}
{{ end }}
2018-07-27 23:06:12 +00:00
<!-- resolve absolute image path -->
{{ $permalink := $.Page.Permalink }}
{{ $image := .Get "src" }}
{{ $image_link_absolute := (findRE "^/" $image) }}
2018-07-21 07:08:41 +00:00
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
2018-07-27 23:06:12 +00:00
{{ if .Get "link"}}
<a href="{{ .Get "link" }}"
{{ with .Get "target" }} target="{{ . }}"{{ end }}
{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{ end }}
<img
{{ if $image_link_absolute }}
src="{{ $image | absURL }}"
{{ else }}
src="{{ (printf "%s%s" $permalink $image) }}"
{{ end }}
{{ if .Get "alt" }}alt="{{ .Get "alt" | markdownify | plainify }}"
{{- else if .Get "caption" }}alt="{{ .Get "caption" | markdownify | plainify }}"
{{- end }}
{{ with .Get "align" }}align="{{ . }}"{{ end }}
2018-07-27 23:06:12 +00:00
width="{{ .Get "width" | default "100%"}}"
{{ with .Get "height" }}width="{{ . }}"{{ end }} />
{{ if .Get "link"}}</a>{{ end }}
<!-- caption and attr-->
{{ if ($fig.Get "caption") }}
2018-07-21 07:08:41 +00:00
<figcaption>
2018-07-27 23:06:12 +00:00
<span class="img--caption">
Figure {{ $.Page.Scratch.Get "fig" }}. {{ $fig.Get "caption" | markdownify | plainify }}
{{ if .Get "attr" }}
[{{- with .Get "attrlink"}}<a href="{{ . | markdownify }}">{{ end -}}
{{ .Get "attr" | markdownify }}
{{- if .Get "attrlink"}}</a>{{- end }}]
{{ end }}
</span>
2018-07-21 07:08:41 +00:00
</figcaption>
{{ end }}
2018-07-21 07:08:41 +00:00
</figure>
{{ .Page.Scratch.Add "fig" 1 }}
{{ $fig.Delete "caption"}}