From 3e01b66d29ff29ae1d735c419e984e88b981027b Mon Sep 17 00:00:00 2001 From: Nedjo Rogers Date: Wed, 13 Apr 2022 12:11:11 -0700 Subject: [PATCH] Support absolute paths for image resources (#362) --- layouts/partials/func/GetFeaturedImage.html | 6 ++++-- layouts/shortcodes/figure.html | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/layouts/partials/func/GetFeaturedImage.html b/layouts/partials/func/GetFeaturedImage.html index 51aa8c0..bb3b6ba 100644 --- a/layouts/partials/func/GetFeaturedImage.html +++ b/layouts/partials/func/GetFeaturedImage.html @@ -27,12 +27,14 @@ {{ end }} {{ else }} {{/* If we find a local global Resource matching the exact value, we use it. */}} - {{ with resources.GetMatch . }} + {{/* Matching uses relative paths so strip a leading / character if present. */}} + {{ with resources.GetMatch (trim . "/") }} {{ $coverImage = . }} {{ end }} {{ end }} {{/* If we find a Page Resource matching the exact value, we use it instead. */}} - {{ with $.Resources.GetMatch . }} + {{/* Matching uses relative paths so strip a leading / character if present. */}} + {{ with $.Resources.GetMatch (trim . "/") }} {{ $coverImage = . }} {{ end }} {{/* Find the first image with 'cover' in the name in this page bundle. */}} diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index 25ca905..e706af8 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -1,5 +1,6 @@ {{ $srcset := slice }} -{{- with .Page.Resources.GetMatch (.Get "src") -}} +{{/* Matching uses relative paths so strip a leading / character if present. */}} +{{- with .Page.Resources.GetMatch (trim (.Get "src") "/") -}} {{- /* Standard width of main is 70% (w-70-ns) */ -}} {{- $target_width := 0.70 -}} {{ $srcset = partial "func/GetImageSrcset" (dict "original" . "target_width" $target_width) }}