Skip to content

Commit

Permalink
Improved figure shortcode, no -1px round of errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
frjo committed Sep 8, 2018
1 parent b1f724e commit 7379575
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions layouts/shortcodes/figure.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down

0 comments on commit 7379575

Please sign in to comment.