From fdb7bbd3c099459b6128dd3dc5cad9b392a8e3d9 Mon Sep 17 00:00:00 2001 From: Graeme A Stewart Date: Tue, 5 Mar 2024 13:57:04 +0100 Subject: [PATCH] Add target parameter to figure shortcode Add the "target" parameter to the figure.html shortcode. If defined then add this target property to the href of the figure, which allows the link to, e.g., open in a new tab. Add description of target to docs --- exampleSite/content/docs/shortcodes/index.md | 1 + layouts/shortcodes/figure.html | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/exampleSite/content/docs/shortcodes/index.md b/exampleSite/content/docs/shortcodes/index.md index 8e7b9283..8c9bba1e 100644 --- a/exampleSite/content/docs/shortcodes/index.md +++ b/exampleSite/content/docs/shortcodes/index.md @@ -204,6 +204,7 @@ The `figure` shortcode accepts six parameters: | `caption` | Markdown for the image caption, which will be displayed below the image. | | `class` | Additional CSS classes to apply to the image. | | `href` | URL that the image should be linked to. | +| `target` | The target attribute for the `href` URL. | | `nozoom` | `nozoom=true` disables the image "zoom" functionality. This is most useful in combination with a `href` link. | | `default` | Special parameter to revert to default Hugo `figure` behaviour. Simply provide `default=true` and then use normal [Hugo shortcode syntax](https://gohugo.io/content-management/shortcodes/#figure). | diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html index c916c9dc..4f641f3b 100644 --- a/layouts/shortcodes/figure.html +++ b/layouts/shortcodes/figure.html @@ -7,6 +7,7 @@ {{ $caption := .Get "caption" }} {{ $href := .Get "href" }} {{ $class := .Get "class" }} + {{ $target := .Get "target" }} {{ $nozoom := .Get "nozoom" | default false }} {{ if findRE "^https?" $url.Scheme }}
@@ -22,7 +23,7 @@ {{ end }} {{ with $resource }}
- {{ with $href }}{{ end }} + {{ with $href }}{{ end }} {{ if $disableImageOptimization }}