43 lines
2.2 KiB
HTML
43 lines
2.2 KiB
HTML
{{ $maxwidth := .Site.Params.imageMaxWidth -}}
|
|
{{ with (imageConfig (add "/static/" (.Get "src"))) -}}
|
|
{{ $.Scratch.Set "realwidth" .Width -}}
|
|
{{ $.Scratch.Set "realheight" .Height -}}
|
|
{{ $.Scratch.Set "width" .Width -}}
|
|
{{ $.Scratch.Set "height" .Height -}}
|
|
{{ end -}}
|
|
{{ if and (.Get "width") (.Get "height") -}}
|
|
{{ $.Scratch.Set "width" (int (.Get "width")) -}}
|
|
{{ $.Scratch.Set "height" (int (.Get "height")) -}}
|
|
{{ else if (.Get "width") -}}
|
|
{{ $.Scratch.Set "width" (int (.Get "width")) -}}
|
|
{{ if lt ($.Scratch.Get "width") ($.Scratch.Get "realwidth") -}}
|
|
{{ $height := (mul ($.Scratch.Get "realheight") (div (add ($.Scratch.Get "width") 0.0) ($.Scratch.Get "realwidth"))) -}}
|
|
{{ $.Scratch.Set "height" (math.Round $height) -}}
|
|
{{ end -}}
|
|
{{ else if (.Get "height") -}}
|
|
{{ $.Scratch.Set "height" (int (.Get "height")) -}}
|
|
{{ if lt ($.Scratch.Get "height") ($.Scratch.Get "realheight") -}}
|
|
{{ $width := (mul ($.Scratch.Get "realwidth") (div (add ($.Scratch.Get "height") 0.0) ($.Scratch.Get "realheight"))) -}}
|
|
{{ $.Scratch.Set "width" (math.Round $width) -}}
|
|
{{ end -}}
|
|
{{ else if and $maxwidth (lt $maxwidth ($.Scratch.Get "width")) -}}
|
|
{{ $.Scratch.Set "width" $maxwidth -}}
|
|
{{ $height := (mul ($.Scratch.Get "realheight") (div (add ($.Scratch.Get "width") 0.0) ($.Scratch.Get "realwidth"))) -}}
|
|
{{ $.Scratch.Set "height" (math.Round $height) -}}
|
|
{{ end -}}
|
|
<figure class="image {{ .Get "class" | default "" }}">
|
|
{{ with .Get "link" }}<a href="{{ . }}">{{ end -}}
|
|
<img src="{{ .Get "src" | relURL }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" }}{{ end }}"{{ end }}{{ with $.Scratch.Get "width" }} width="{{ . }}"{{ end }}{{ with $.Scratch.Get "height" }} height="{{ . }}"{{ end }}>
|
|
{{- if .Get "link" }}</a>{{ end }}
|
|
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
|
|
<figcaption>{{ if isset .Params "title" }}
|
|
<h4>{{ .Get "title" }}</h4>{{ end }}
|
|
{{ if or (.Get "caption") (.Get "attr") -}}
|
|
<p>
|
|
{{- .Get "caption" -}}
|
|
{{ with .Get "attrlink" }} <a href="{{ . }}">{{ end }}{{ .Get "attr" }}{{ if .Get "attrlink" }}</a>{{ end -}}
|
|
</p>
|
|
{{ end -}}
|
|
</figcaption>
|
|
{{ end -}}
|
|
</figure>
|