diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index 4f8dbfd..0e71cd1 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -1,6 +1,22 @@ +{{ $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 (.Get "width") -}} + {{ $.Scratch.Set "width" (int (.Get "width")) -}} +{{ else if lt $maxwidth ($.Scratch.Get "width") -}} + {{ $.Scratch.Set "width" $maxwidth -}} +{{ end -}} +{{ 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" (int $height) -}} +{{ end -}} {{ with .Get "link" }}{{ end -}} - + {{- if .Get "link" }}{{ end }} {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} {{ if isset .Params "title" }} @@ -8,7 +24,7 @@ {{ if or (.Get "caption") (.Get "attr") -}} {{- .Get "caption" -}} -{{ with .Get "attrlink" }} {{ end }}{{ .Get "attr" }}{{ if .Get "attrlink"}}{{ end -}} +{{ with .Get "attrlink" }} {{ end }}{{ .Get "attr" }}{{ if .Get "attrlink" }}{{ end -}} {{ end -}}
{{- .Get "caption" -}} -{{ with .Get "attrlink" }} {{ end }}{{ .Get "attr" }}{{ if .Get "attrlink"}}{{ end -}} +{{ with .Get "attrlink" }} {{ end }}{{ .Get "attr" }}{{ if .Get "attrlink" }}{{ end -}}