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

markdownify resolves page resources to home instead of current page when render hooks are present #9692

Open
jmooring opened this issue Mar 18, 2022 · 5 comments
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Mar 18, 2022

The result is either a missing resource or the wrong resource. This is limited to the markdownify function... .Page.RenderString works as expected.

The problem occurs with v0.93.0 and later.

structure

content/
├── test/
│   ├── a.jpg
│   └── index.md
├── b.jpg
└── _index.md

content/test/index.md

{{< img "![kitten](a.jpg)" >}}

layouts/shortcodes/img.html

{{ .Get 0 | markdownify }}

layouts/_default/_markup/render-image.html

{{ with $i := .Page.Resources.GetMatch .Destination }}
  <img src="{{ .RelPermalink }}">
{{ else }}
  {{ errorf "Unable to get %q as a page resource" .Destination }}
{{ end }}

When you run hugo, the result is:

ERROR 2022/03/18 08:46:47 Unable to get "a.jpg" as a page resource

If you do this...

mv content/b.jpg content/a.jpg

...the site builds but the wrong image is displayed.

Example:

git clone --single-branch -b hugo-github-issue-9692 https://github.com/jmooring/hugo-testing hugo-github-issue-9692
cd hugo-github-issue-9692
hugo 

Reference: https://discourse.gohugo.io/t/37735

@bep
Copy link
Member

bep commented Mar 18, 2022

This is a known limitation (or at least known to me, but I think I have shouted about it). This was somewhat a catch 22 situation and needed to be able to implement render hooks for code blocks. When I get to finish #9570 I can make this work as expected (then I have global access to "the current page", as it is now we always use the home page for markdownify), but until then I would recommend people with advanced markdownify needs to use .Page.RenderString etc.

@jmooring
Copy link
Member Author

I understand. I just wanted to make sure this was being tracked somewhere.

@jmooring jmooring changed the title markdowninfy resolves page resources to home instead of current page when render hooks are present markdownify resolves page resources to home instead of current page when render hooks are present Mar 18, 2022
JackuB added a commit to JackuB/hugo that referenced this issue Jan 31, 2023
JackuB added a commit to JackuB/hugo that referenced this issue Feb 3, 2023
JackuB added a commit to JackuB/hugo that referenced this issue Feb 3, 2023
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@github-actions github-actions bot added the Stale label Mar 19, 2023
@jmooring jmooring added Keep and removed Stale labels Mar 19, 2023
@willfaught
Copy link

My use case is a render hook for links that checks whether the current page has a parameter set that makes all external links open in a new tab. It would be great if markdownify worked everywhere.

@ytrepidorosonomous
Copy link

Pull request closed #9570

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants