Permalink
Browse files

Improved figure shortcode, no -1px round of errors.

  • Loading branch information...
frjo committed Sep 8, 2018
1 parent b1f724e commit 73795756ac8062f63cfbd0c91887b45e34654add
Showing with 15 additions and 11 deletions.
  1. +15 −11 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 -}}
<figure {{ with .Get "class" }}class="{{ . }}"{{ end }}>
{{ with .Get "link" }}<a href="{{ . }}">{{ end -}}

0 comments on commit 7379575

Please sign in to comment.