From f55ff594c0f63899a8af893f33bd62ceb77cc8fd Mon Sep 17 00:00:00 2001 From: Federico Agostini <43784886+Agos95@users.noreply.github.com> Date: Mon, 13 Feb 2023 21:03:01 +0100 Subject: [PATCH] fix: shortcode context for v2 blocks (#2919) Shortcodes in the new block system do not get access to the correct .Page variable (see #2918 ). The problem is the use of markdownify function to parse $block.content.text, since it actually is an alias to site.Home.RenderString since v 0.93.0 (see gohugoio/hugo#9959 (comment)). This causes the shortcodes to always get the Homepage as .Page variable. The fix is to substitute markdownify with $page.RenderString, which gives the correct context. Fixes #2918 --- modules/wowchemy/layouts/partials/blocks/about.avatar.html | 2 +- modules/wowchemy/layouts/partials/blocks/accomplishments.html | 2 +- modules/wowchemy/layouts/partials/blocks/collection.html | 2 +- modules/wowchemy/layouts/partials/blocks/contact.html | 2 +- modules/wowchemy/layouts/partials/blocks/experience.html | 2 +- modules/wowchemy/layouts/partials/blocks/features.html | 2 +- modules/wowchemy/layouts/partials/blocks/hero.html | 2 +- modules/wowchemy/layouts/partials/blocks/markdown.html | 2 +- modules/wowchemy/layouts/partials/blocks/portfolio.html | 2 +- modules/wowchemy/layouts/partials/blocks/tag_cloud.html | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/wowchemy/layouts/partials/blocks/about.avatar.html b/modules/wowchemy/layouts/partials/blocks/about.avatar.html index f43c3228..ee554fdb 100644 --- a/modules/wowchemy/layouts/partials/blocks/about.avatar.html +++ b/modules/wowchemy/layouts/partials/blocks/about.avatar.html @@ -82,7 +82,7 @@ {{ end }} - {{ with ($block.content.text | emojify | markdownify) | default $person_page.Content }} + {{ with ($block.content.text | emojify | $page.RenderString) | default $person_page.Content }}
{{ . }} diff --git a/modules/wowchemy/layouts/partials/blocks/accomplishments.html b/modules/wowchemy/layouts/partials/blocks/accomplishments.html index 887b8272..43d2693d 100644 --- a/modules/wowchemy/layouts/partials/blocks/accomplishments.html +++ b/modules/wowchemy/layouts/partials/blocks/accomplishments.html @@ -9,7 +9,7 @@
- {{ with $block.Content }}{{ . }}{{ end }} + {{ with $block.content.text }}{{ . | emojify | $page.RenderString }}{{ end }} {{ if $block.content.items }} {{ range $idx, $key := sort $block.content.items ".date_start" "desc" }} diff --git a/modules/wowchemy/layouts/partials/blocks/collection.html b/modules/wowchemy/layouts/partials/blocks/collection.html index 80b4bbb7..c0ae33a4 100644 --- a/modules/wowchemy/layouts/partials/blocks/collection.html +++ b/modules/wowchemy/layouts/partials/blocks/collection.html @@ -78,7 +78,7 @@
- {{ with $block.content.text }}{{ . | emojify | markdownify }}{{ end }} + {{ with $block.content.text }}{{ . | emojify | $page.RenderString }}{{ end }} {{ range $index, $item := $query }} {{ partial "functions/render_view" (dict "page" $block "item" . "view" ($block.design.view | default "compact") "index" $index) }} diff --git a/modules/wowchemy/layouts/partials/blocks/contact.html b/modules/wowchemy/layouts/partials/blocks/contact.html index ce2b96ca..22de1cb2 100644 --- a/modules/wowchemy/layouts/partials/blocks/contact.html +++ b/modules/wowchemy/layouts/partials/blocks/contact.html @@ -24,7 +24,7 @@ {{ end }}
- {{ with $block.content.text }}{{ . }}{{ end }} + {{ with $block.content.text }}{{ . | emojify | $page.RenderString }}{{ end }} {{ if $use_form }} diff --git a/modules/wowchemy/layouts/partials/blocks/experience.html b/modules/wowchemy/layouts/partials/blocks/experience.html index ae01fce0..b86b96a2 100644 --- a/modules/wowchemy/layouts/partials/blocks/experience.html +++ b/modules/wowchemy/layouts/partials/blocks/experience.html @@ -9,7 +9,7 @@
- {{ with $block.content.text }}{{ . | emojify | markdownify }}{{ end }} + {{ with $block.content.text }}{{ . | emojify | $page.RenderString }}{{ end }} {{ if $block.content.items }} {{ $exp_len := len $block.content.items }} diff --git a/modules/wowchemy/layouts/partials/blocks/features.html b/modules/wowchemy/layouts/partials/blocks/features.html index 867b8a43..19f969c0 100644 --- a/modules/wowchemy/layouts/partials/blocks/features.html +++ b/modules/wowchemy/layouts/partials/blocks/features.html @@ -16,7 +16,7 @@ {{ with $block.content.text }}
- {{ . | emojify | markdownify }} + {{ . | emojify | $page.RenderString }}
{{ end }} diff --git a/modules/wowchemy/layouts/partials/blocks/hero.html b/modules/wowchemy/layouts/partials/blocks/hero.html index 7f0286c6..2bb662b4 100644 --- a/modules/wowchemy/layouts/partials/blocks/hero.html +++ b/modules/wowchemy/layouts/partials/blocks/hero.html @@ -17,7 +17,7 @@ {{ end }} {{ with $block.content.text }} -
{{ . | markdownify | emojify }}
+
{{ . | $page.RenderString | emojify }}
{{ end }} {{/* Call-to-action link */}} diff --git a/modules/wowchemy/layouts/partials/blocks/markdown.html b/modules/wowchemy/layouts/partials/blocks/markdown.html index 7ae6708f..76f8d48e 100644 --- a/modules/wowchemy/layouts/partials/blocks/markdown.html +++ b/modules/wowchemy/layouts/partials/blocks/markdown.html @@ -6,7 +6,7 @@ {{ $page := .wcPage }} {{ $block := .wcBlock }} {{ $columns := $block.design.columns | default "1" }} -{{ $text := $block.content.text | emojify | markdownify }} +{{ $text := $block.content.text | emojify | $page.RenderString }} {{ if ne $columns "1" }}
diff --git a/modules/wowchemy/layouts/partials/blocks/portfolio.html b/modules/wowchemy/layouts/partials/blocks/portfolio.html index 05a14d89..702daa25 100644 --- a/modules/wowchemy/layouts/partials/blocks/portfolio.html +++ b/modules/wowchemy/layouts/partials/blocks/portfolio.html @@ -13,7 +13,7 @@
- {{ with $block.content.text }}{{ . | markdownify }}{{ end }} + {{ with $block.content.text }}{{ . | $page.RenderString | emojify }}{{ end }} {{ if $block.content.buttons }} diff --git a/modules/wowchemy/layouts/partials/blocks/tag_cloud.html b/modules/wowchemy/layouts/partials/blocks/tag_cloud.html index dd43a334..f1cf9b6b 100644 --- a/modules/wowchemy/layouts/partials/blocks/tag_cloud.html +++ b/modules/wowchemy/layouts/partials/blocks/tag_cloud.html @@ -23,7 +23,7 @@ {{ $columns := $block.design.columns | default "1" }}
- {{ with $block.content.text }}{{ . | markdownify }}{{ end }} + {{ with $block.content.text }}{{ . | $page.RenderString | emojify }}{{ end }} {{ if ne $count 0 }}