From 73795756ac8062f63cfbd0c91887b45e34654add Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Sat, 8 Sep 2018 19:34:29 +0200 Subject: [PATCH] Improved figure shortcode, no -1px round of errors. --- layouts/shortcodes/figure.html | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index fbf3da1..4d82ead 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -5,21 +5,25 @@ {{ $.Scratch.Set "width" .Width -}} {{ $.Scratch.Set "height" .Height -}} {{ end -}} -{{ if (.Get "width") -}} +{{ 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 -}} -{{ 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 -}} -{{ if (.Get "height") -}} - {{ $.Scratch.Set "height" (int (.Get "height")) -}} -{{ end -}} -{{ 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" (int $width) -}} + {{ $.Scratch.Set "height" (math.Round $height) -}} {{ end -}}
{{ with .Get "link" }}{{ end -}}