From a9d822a15682c8a639cf8cb1c641b4281b5eba2a Mon Sep 17 00:00:00 2001 From: Will Faught Date: Tue, 25 Apr 2023 19:16:55 -0700 Subject: [PATCH] Fix shortcodes to enable complex nesting --- .../content/shortcodes/gallery/index.md | 4 +++ layouts/partials/paige/image.html | 3 +- layouts/partials/paige/link.html | 3 +- layouts/partials/paige/links.html | 2 +- layouts/partials/paige/resource.html | 11 ++++--- layouts/partials/paige/script.html | 3 +- layouts/partials/paige/scripts.html | 6 ++-- layouts/shortcodes/paige/figure.html | 14 ++++---- layouts/shortcodes/paige/gallery.html | 32 +++++++++++-------- layouts/shortcodes/paige/image.html | 1 + 10 files changed, 49 insertions(+), 30 deletions(-) diff --git a/exampleSite/content/shortcodes/gallery/index.md b/exampleSite/content/shortcodes/gallery/index.md index a60c1c03..1a0642d6 100644 --- a/exampleSite/content/shortcodes/gallery/index.md +++ b/exampleSite/content/shortcodes/gallery/index.md @@ -369,6 +369,7 @@ Result: Code: ```go-text-template +{{}} {{}} {{}} {{}} @@ -383,10 +384,12 @@ Code: {{}} {{}} {{}} +{{}} ``` Result: +{{< paige/figure caption="Gallery" >}} {{< paige/gallery >}} {{< paige/figure caption="Image 1" >}} {{< paige/image src="1-2.jpg" >}} @@ -401,3 +404,4 @@ Result: {{< paige/image src="4.jpg" >}} {{< /paige/figure >}} {{< /paige/gallery >}} +{{< /paige/figure >}} diff --git a/layouts/partials/paige/image.html b/layouts/partials/paige/image.html index 5377249e..996bde58 100644 --- a/layouts/partials/paige/image.html +++ b/layouts/partials/paige/image.html @@ -11,6 +11,7 @@ {{ $loading := $params.loading }} {{ $maxheight := $params.maxheight }} {{ $maxwidth := $params.maxwidth }} +{{ $page := $params.page }} {{ $process := $params.process }} {{ $resource := $params.resource }} {{ $sizes := $params.sizes }} @@ -68,7 +69,7 @@ {{ $style = delimit ($style | uniq | sort) "; " }} {{ if and (not $resource) $src }} - {{ $resource = partial "paige/resource.html" $src }} + {{ $resource = partial "paige/resource.html" (dict "page" $page "url" $src) }} {{ end }} {{ if $resource }} diff --git a/layouts/partials/paige/link.html b/layouts/partials/paige/link.html index d4b2108e..5d05090a 100644 --- a/layouts/partials/paige/link.html +++ b/layouts/partials/paige/link.html @@ -4,6 +4,7 @@ {{ $href := $params.href }} {{ $includepaths := $params.includepaths }} {{ $integrity := $params.integrity }} +{{ $page := $params.page }} {{ $referrerpolicy := $params.referrerpolicy | default "no-referrer" }} {{ $sass := $params.sass }} {{ $template := $params.template }} @@ -15,7 +16,7 @@ {{ errorf "layouts/partials/paige/link.html: no href" }} {{ end }} -{{ with partial "paige/resource.html" $href }} +{{ with partial "paige/resource.html" (dict "page" $page "url" $href) }} {{ $resource := . }} {{ if $template }} diff --git a/layouts/partials/paige/links.html b/layouts/partials/paige/links.html index 98f13f24..8cfe45fd 100644 --- a/layouts/partials/paige/links.html +++ b/layouts/partials/paige/links.html @@ -33,7 +33,7 @@ {{ end }} {{ partial "paige/link.html" (dict "href" "css/paige/bootstrap/paige.scss" "page" $page "sass" true "template" true) }} -{{ partial "paige/link.html" (dict "href" "css/paige/bootstrap-icons/bootstrap-icons.css") }} +{{ partial "paige/link.html" (dict "href" "css/paige/bootstrap-icons/bootstrap-icons.css" "page" $page) }} {{ if $page.Param "paige.math" }} {{ partial "paige/link.html" (dict "href" "css/paige/katex/katex.min.css") }} diff --git a/layouts/partials/paige/resource.html b/layouts/partials/paige/resource.html index 60edc971..0ad1101a 100644 --- a/layouts/partials/paige/resource.html +++ b/layouts/partials/paige/resource.html @@ -1,4 +1,7 @@ -{{ $url := . }} +{{ $params := . }} + +{{ $page := $params.page }} +{{ $url := $params.url }} {{ $result := "" }} @@ -12,11 +15,11 @@ {{ end }} {{ end }} -{{ if and (not $result) page }} - {{ with page.Resources.GetMatch $url }} +{{ if and (not $result) $page }} + {{ with $page.Resources.GetMatch $url }} {{ $result = . }} {{ else }} - {{ with page.Resources.Get $url }} + {{ with $page.Resources.Get $url }} {{ $result = . }} {{ end }} {{ end }} diff --git a/layouts/partials/paige/script.html b/layouts/partials/paige/script.html index 93998d9a..3f5d95b9 100644 --- a/layouts/partials/paige/script.html +++ b/layouts/partials/paige/script.html @@ -4,6 +4,7 @@ {{ $defer := $params.defer | default "defer" }} {{ $integrity := $params.integrity }} {{ $onload := $params.onload | safeJS }} +{{ $page := $params.page }} {{ $referrerpolicy := $params.referrerpolicy | default "no-referrer" }} {{ $src := $params.src }} {{ $type := $params.type }} @@ -12,7 +13,7 @@ {{ errorf "layouts/partials/paige/script.html: no src" }} {{ end }} -{{ with partial "paige/resource.html" $src }} +{{ with partial "paige/resource.html" (dict "page" $page "url" $src) }} {{ $resource := . | minify | fingerprint }} {{ $integrity = $resource.Data.Integrity }} {{ $src = $resource.RelPermalink }} diff --git a/layouts/partials/paige/scripts.html b/layouts/partials/paige/scripts.html index 2be2bc8c..0419fc71 100644 --- a/layouts/partials/paige/scripts.html +++ b/layouts/partials/paige/scripts.html @@ -28,11 +28,11 @@ function paigeResize() { paigeResize(); addEventListener("resize", paigeResize); -{{ partial "paige/script.html" (dict "src" "js/paige/bootstrap/bootstrap.bundle.js") }} +{{ partial "paige/script.html" (dict "page" $page "src" "js/paige/bootstrap/bootstrap.bundle.js") }} {{ if $page.Param "paige.math" }} - {{ partial "paige/script.html" (dict "src" "js/paige/katex/katex.min.js") }} - {{ partial "paige/script.html" (dict "onload" "renderMathInElement(document.body);" "src" "js/paige/katex/auto-render.min.js") }} + {{ partial "paige/script.html" (dict "page" $page "src" "js/paige/katex/katex.min.js") }} + {{ partial "paige/script.html" (dict "onload" "renderMathInElement(document.body);" "page" $page "src" "js/paige/katex/auto-render.min.js") }} {{ end }} {{ partial "paige/analytics.html" $page }} diff --git a/layouts/shortcodes/paige/figure.html b/layouts/shortcodes/paige/figure.html index 812d0116..f1c1d299 100644 --- a/layouts/shortcodes/paige/figure.html +++ b/layouts/shortcodes/paige/figure.html @@ -54,12 +54,14 @@ {{ end }} {{ end }} +{{/* The markup below cannot be indented due to Markdown. */}} +
-
-
{{ $content }}
+
+
{{ $content }}
- {{ if $showcaption }} -
{{ $caption }}
- {{ end }} -
+{{ if $showcaption }} +
{{ $caption }}
+{{ end }} +
diff --git a/layouts/shortcodes/paige/gallery.html b/layouts/shortcodes/paige/gallery.html index c245305b..fe3041ac 100644 --- a/layouts/shortcodes/paige/gallery.html +++ b/layouts/shortcodes/paige/gallery.html @@ -10,6 +10,7 @@ {{ $loading := .Get "loading" }} {{ $maxheight := .Get "maxheight" }} {{ $maxwidth := .Get "maxwidth" }} +{{ $page := .Page }} {{ $process := .Get "process" }} {{ $style := .Get "style" }} {{ $type := .Get "type" | default "rows" }} @@ -38,14 +39,16 @@ {{ end }} {{ end }} +{{/* The markup below cannot be indented due to Markdown. */}} +