From 361e62d334296300df763be9f4394d9ecb4de79b Mon Sep 17 00:00:00 2001 From: Will Faught Date: Wed, 28 Dec 2022 23:50:27 -0800 Subject: [PATCH] Change figure shortcode to use relative paths as page resources --- README.md | 1 + layouts/shortcodes/paige/figure.html | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2ca0979..fa590cbd 100644 --- a/README.md +++ b/README.md @@ -455,6 +455,7 @@ The `paige/figure` shortcode provides a figure with a centered image and an opti The image and caption can optionally be displayed inline instead of centered. The image has optional alt, title, width, and height attributes, and can optionally be wrapped in an anchor. Only the image source parameter is required. +If the image source is a relative path, it is assumed to be a page resource. These are the named parameters with positions, listed in the order of their positions: diff --git a/layouts/shortcodes/paige/figure.html b/layouts/shortcodes/paige/figure.html index 03f7e2d1..5c0a5323 100644 --- a/layouts/shortcodes/paige/figure.html +++ b/layouts/shortcodes/paige/figure.html @@ -3,7 +3,14 @@ {{ with $link }} {{ end }} - + {{ $src := .Get 0 | default (.Get `src`) }} + {{ $url := urls.Parse $src }} + {{ if and (not $url.IsAbs) (not (hasPrefix $url.Path "/")) }} + {{ with .Page.Resources.GetMatch $src }} + {{ $src = .RelPermalink }} + {{ end }} + {{ end }} + {{ if $link }} {{ end }}