From 545ae028ff93edba9975cd4433eab90eaadc01a0 Mon Sep 17 00:00:00 2001 From: Zachary Betz Date: Wed, 13 Feb 2019 13:54:04 -0600 Subject: [PATCH] Shortcodes for figure and gallery --- layouts/shortcodes/figure.html | 27 ++++++++++++++++----------- layouts/shortcodes/gallery.html | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 layouts/shortcodes/gallery.html diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index fff42ad..90bf2e6 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -1,23 +1,28 @@ -{{ $original := .Page.Resources.GetMatch (printf "*%s*" (.Get "img")) }} +{{ $img := .Get "img" }} +{{ $caption := .Get "caption" }} +{{ $command := .Get "command" }} +{{ $options := .Get "options" }} + +{{ $original := .Page.Resources.GetMatch (printf "*%s*" $img) }} {{ $new := "" }} -{{ if eq (.Get "command") "Fit" }} - {{ $new = $original.Fit (.Get "options") }} -{{ else if eq (.Get "command") "Fill" }} - {{ $new = $original.Fill (.Get "options") }} -{{ else if eq (.Get "command") "Resize" }} - {{ $new = $original.Resize (.Get "options") }} -{{ else if eq (.Get "command") "Original" }} +{{ if eq $command "Fit" }} + {{ $new = $original.Fit $options }} +{{ else if eq $command "Fill" }} + {{ $new = $original.Fill $options }} +{{ else if eq $command "Resize" }} + {{ $new = $original.Resize $options }} +{{ else if eq $command "Original" }} {{ $new = $original }} {{ else }} {{ errorf "Invalid image processing command: Must be one of Fit, Fill, Resize, Original." }} {{ end }} -
+
-
- {{ (.Get "caption") | markdownify }} +
+ {{ $caption | markdownify }}
diff --git a/layouts/shortcodes/gallery.html b/layouts/shortcodes/gallery.html new file mode 100644 index 0000000..d3e972e --- /dev/null +++ b/layouts/shortcodes/gallery.html @@ -0,0 +1,29 @@ +{{ $command := .Get "command" }} +{{ $options := .Get "options" }} + +{{ with .Page.Resources.ByType "image" }} + {{ range . }} + + {{ $original := . }} + {{ $new := "" }} + + {{ if eq $command "Fit" }} + {{ $new = $original.Fit $options }} + {{ else if eq $command "Fill" }} + {{ $new = $original.Fill $options }} + {{ else if eq $command "Resize" }} + {{ $new = $original.Resize $options }} + {{ else if eq $command "Original" }} + {{ $new = $original }} + {{ else }} + {{ errorf "Invalid image processing command: Must be one of Fit, Fill, Resize, Original." }} + {{ end }} + + + + {{ end }} +{{ end }}