From 474796c20420ca91ad3e2e02abe12a7d5f0f3607 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Mon, 20 Apr 2020 20:43:51 +0200 Subject: [PATCH] Make the figure shortcode work with images not in static. --- layouts/shortcodes/figure.html | 39 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index df97c66..1a30751 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -3,43 +3,46 @@ {{ $realheight := 0 -}} {{ $width := 0 -}} {{ $height := 0 -}} -{{ with (imageConfig (add "/static/" (.Get "src"))) -}} +{{ $height := 0 -}} +{{ if (fileExists (add "/static" (.Get "src"))) -}} + {{ with (imageConfig (add "/static" (.Get "src"))) -}} {{ $realwidth = .Width -}} {{ $realheight = .Height -}} {{ $width = .Width -}} {{ $height = .Height -}} + {{ end -}} {{ end -}} {{ if and (.Get "width") (.Get "height") -}} {{ $width = (int (.Get "width")) -}} {{ $height = (int (.Get "height")) -}} -{{ else if (.Get "width") -}} - {{ $width = (int (.Get "width")) -}} - {{ if lt ($width) ($realwidth) -}} - {{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}} - {{ $height = (math.Round $height) -}} - {{ end -}} -{{ else if (.Get "height") -}} - {{ $height = (int (.Get "height")) -}} - {{ if lt ($height) ($realheight) -}} - {{ $width = (mul ($realwidth) (div (add ($height) 0.0) ($realheight))) -}} - {{ $width = (math.Round $width) -}} - {{ end -}} -{{ else if and ($maxwidth) (lt ($maxwidth) ($width)) -}} - {{ $width = ($maxwidth) -}} +{{ else if (.Get "width") -}} + {{ $width = (int (.Get "width")) -}} + {{ if and ($realwidth) (lt ($width) ($realwidth)) -}} {{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}} {{ $height = (math.Round $height) -}} + {{ end -}} +{{ else if (.Get "height") -}} + {{ $height = (int (.Get "height")) -}} + {{ if and ($realheight) (lt ($height) ($realheight)) -}} + {{ $width = (mul ($realwidth) (div (add ($height) 0.0) ($realheight))) -}} + {{ $width = (math.Round $width) -}} + {{ end -}} +{{ else if and ($maxwidth) (lt ($maxwidth) ($width)) -}} + {{ $width = ($maxwidth) -}} + {{ $height = (mul ($realheight) (div (add ($width) 0.0) ($realwidth))) -}} + {{ $height = (math.Round $height) -}} {{ end -}}
{{ with .Get "link" }}{{ end -}} - + {{- if .Get "link" }}{{ end }} -{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}} +{{ if or (or (.Get "title") (.Get "caption" | markdownify)) (.Get "attr") -}}
{{ if isset .Params "title" }}

{{ .Get "title" }}

{{ end }} {{ if or (.Get "caption") (.Get "attr") -}}

{{- .Get "caption" -}} -{{ with .Get "attrlink" }}{{ end }}{{ .Get "attr" }}{{ if .Get "attrlink" }}{{ end -}} +{{ with .Get "attrlink" }}{{ end }}{{ .Get "attr" | markdownify }}{{ if .Get "attrlink" }}{{ end -}}

{{ end -}}