12345678910111213141516171819202122232425262728293031323334353637383940 |
- <!-- https://github.com/gohugoio/hugo/issues/4406 -->
- <!-- https://github.com/gohugoio/hugo/issues/4562 -->
- {{ $image := .Get "src" }}
- <figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
- {{ if .Get "link"}}<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>{{ end }}
- {{ if (findRE "(^|:)//" $image) -}} <!-- If image link is a URL with protocol or two leading slashes, use just that unmodified. -->
- <img src="{{ $image }}"
- {{- else if (findRE "^/" $image) -}} <!-- If image link has one leading slash -->
- {{- /* Cannot use absURL below because it doesn't work as expected if baseURL has a subdir. */ -}}
- {{- $baseurl_no_trailing_slash := $.Site.BaseURL | replaceRE "/$" "" -}}
- <img src="{{ (printf "%s%s" $baseurl_no_trailing_slash $image) }}"
- {{- else -}}
- {{- /* Below variable will always have a trailing slash, even with uglyURLs enabled. */ -}}
- {{- $permalink_pretty := $.Page.Permalink | replaceRE "\\.html$" "/" -}}
- <img src="{{ (printf "%s%s" $permalink_pretty $image) }}"
- {{- end -}}
- {{- if (or (.Get "alt") (.Get "caption")) -}}
- {{- with .Get "alt"}}
- {{- printf " alt=\"%s\"" . | safeHTMLAttr -}}
- {{- else -}}
- {{- printf " alt=\"%s\"" (.Get "caption" | markdownify | plainify) | safeHTMLAttr -}}
- {{- end -}}
- {{- end -}}
- {{- with .Get "width" }} width="{{ . }}"{{ end -}}
- {{- with .Get "height" }} height="{{ . }}"{{ end -}}/> <!-- Closing img tag -->
- {{- if .Get "link" }}</a>{{ end -}}
- {{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
- <figcaption>
- {{ with (.Get "title") }}
- <h4>{{ . }}</h4>
- {{ end }}
- {{ if (or (.Get "caption") (.Get "attr")) }}<p>
- {{ .Get "caption" | markdownify }}
- {{ with .Get "attrlink" }}<a href="{{ . }}"> {{ end }}
- {{ .Get "attr" | markdownify }}
- {{ if .Get "attrlink" }}</a>{{ end }}</p>
- {{ end }}
- </figcaption>
- {{- end -}}
- </figure>
|