Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Shortcode context for v2 blocks #2919

Merged
merged 1 commit into from
Feb 13, 2023

Conversation

Agos95
Copy link
Contributor

@Agos95 Agos95 commented Feb 11, 2023

Purpose

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.

An actual example of this behaviour can be found in this branch (in the csv page):

screenshot_2023-02-11_16-46
screenshot_2023-02-11_16-46_1

This PR fixes #2918.

@netlify
Copy link

netlify bot commented Feb 11, 2023

Deploy Preview for hugo-portfolio-theme canceled.

Name Link
🔨 Latest commit 75c6514
🔍 Latest deploy log https://app.netlify.com/sites/hugo-portfolio-theme/deploys/63e7b8c41494dc00076e1cbc

@netlify
Copy link

netlify bot commented Feb 11, 2023

Deploy Preview for markdown-slides canceled.

Name Link
🔨 Latest commit 75c6514
🔍 Latest deploy log https://app.netlify.com/sites/markdown-slides/deploys/63e7b8c40898b900081c5670

@gcushen
Copy link
Collaborator

gcushen commented Feb 12, 2023

Thanks for contributing a solution 🎉

Before we merge this, can you check if we still need to include the emojify logic or if Hugo is now smart enough to use the emojify: true site setting in config.yaml in its RenderString function?

@gcushen gcushen added the bug label Feb 12, 2023
@gcushen gcushen changed the title Fix Shortcode context for blocks Fix Shortcode context for v2 blocks Feb 12, 2023
@Agos95
Copy link
Contributor Author

Agos95 commented Feb 13, 2023

I tried, but emojify logic is still required to render emoji.

@gcushen gcushen merged commit f55ff59 into HugoBlox:main Feb 13, 2023
@jbsilva jbsilva mentioned this pull request Feb 13, 2023
2 tasks
@Agos95 Agos95 deleted the shortcode-context-fix branch April 28, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shortcodes in FrontMatter don't get the correct .Page variable
2 participants