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

Image render hook does not work with page resources any more #6851

Closed
Brixy opened this issue Feb 4, 2020 · 12 comments
Closed

Image render hook does not work with page resources any more #6851

Brixy opened this issue Feb 4, 2020 · 12 comments

Comments

@Brixy
Copy link

Brixy commented Feb 4, 2020

Image render hook does not work with page resources any more

Hugo 0.64.0 on MacOS Catalina

Yes, this error occurs with latest Hugo version.

Before 0.64 this was possible:

{{ $image := .Page.Resources.GetMatch (printf "%s" (.Destination | safeURL)) }}
{{ $image.RelPermalink }}
{{ $image.Height }}
…

With 0.64 the combination of .Page.Resources and render hooks do not seem to work. Responsive images with markdown render hook are not possible any more.

Error message:

execute of template failed: template: _default/_markup/render-image.html:23:22: executing "_default/_markup/render-image.html" at <$image.RelPermalink>: nil pointer evaluating resource.Resource.RelPermalink

Not quite sure what the reason is; so I cannot tell if this is a bug.

Thanks a lot.

@bep
Copy link
Member

bep commented Feb 4, 2020

I have a test site that builds fine with 0.64 with more or less the same construct as yours:

https://agitated-kilby-da786e.netlify.com/2019/12/30/blog-post/

Meaning there must be "something else" at play in your case.

@Brixy
Copy link
Author

Brixy commented Feb 4, 2020

Thanks for your quick reply, Bep!

{{ with $image }} did the trick. Strangely, this was not necessary before.

Great photo. You live in a beautiful country.

@Brixy Brixy closed this as completed Feb 4, 2020
@bep
Copy link
Member

bep commented Feb 4, 2020

Strangely, this was not necessary before.

I don't see how, but if an image that was found (and displayed) in 0.63 does not show up in 0.64 -- that sounds like a real bug ...?

@Brixy
Copy link
Author

Brixy commented Feb 4, 2020

Ok, now I know what caused the error—testing your code:

In a branch bundle (_index.html/.md file) the .Page.Resources.GetMatch part does not work and it falls back to

{{ else }}
<img src="{{ .Destination | safeURL }}"  alt="{{ $.Text }}" />
{{ end }}

.Page.Resources.GetMatch used to work in 0.63 and before.

Just noticed that this happens with my own image shortcodes, too.

I am reopening this issue because I do not know whether this is intended.

Thanks a lot, @bep!

@Brixy Brixy reopened this Feb 4, 2020
@bep
Copy link
Member

bep commented Feb 4, 2020

@Brixy sure, but as it works for me you need to provide more context. Site source link?

@Brixy
Copy link
Author

Brixy commented Feb 4, 2020

hugo-image-render-hook-test.zip

Attached you find a minimal example.

I simply used your render hook code because this should definitely work. The output part for the image is just

<img src="image.jpg"  alt="Alt text" />

The responsive part is missing completely.

Thanks for investigating.

@Brixy
Copy link
Author

Brixy commented Feb 6, 2020

Just added a figure short code to demonstrate that it fails with .Page.Resources on _index.md, too.

Test repository

Moreover I noticed that the file name now seems to play a role. After renaming some image files in a real project (sorry: the company has not open sourced it) the figure shortcode works.

@hbarthel
Copy link

hbarthel commented Feb 6, 2020

I am using
.Resources.ByType "image"
and also face the issue that there is no image rendered anymore with 0.64.0, with 0.63.2 it worked.

@serg
Copy link

serg commented Feb 7, 2020

The same behavior in my case for Hugo 0.64 extended (Win 64).
Here some test case.
In content/_index.md:

...
resources:
  - src: image.jpg
---

In themes/name-of-theme/layouts/index.html:

{{with .Resources.ByType "image"}}
  <!-- You won't see a message below in browser console -->
  <script>console.log("You have an image");</script>
{{end}}

No building errors appears in Hugo terminal.
@bep, please have a look and resolve when you will have this opportunity.

@onedrawingperday
Copy link
Contributor

onedrawingperday commented Feb 7, 2020

I cannot reproduce the reports in this issue on my end.

In my projects image render hooks with Page Resources called via .Page.Resources.GetMatch work fine in v0.64.0 and v0.65.0-DEV

@Brixy when I test the homepage of your test repo I am seeing a "Yep!" being rendered by your figure shortcode and an image being rendered by the respective Markdown Render Hook template.


@serg it seems to me that you are having a different issue, this one is about Markdown Render Hooks and Page Resources. Not the Homepage template and Page Resources.

May I suggest that you open a support ticket in the forum along while sharing your repo or at least a simplified version .

@bep
Copy link
Member

bep commented Feb 7, 2020

The only relevant change in this Hugo version was to the module/theme file mounts logic. It has plenty of tests, but the devil is in the details (this is esp. true of you consider Windows vs Linux vs MacOs etc.) There is a zip file above that should fail. Someone will look into it soon, and I'm sorry about all of this, but these changes are made with noble motivation, to bring this project forward.

@bep bep added this to the v0.64.1 milestone Feb 9, 2020
@bep bep added Bug and removed NeedsInvestigation labels Feb 9, 2020
bep added a commit to bep/hugo that referenced this issue Feb 9, 2020
bep added a commit to bep/hugo that referenced this issue Feb 9, 2020
@bep bep closed this as completed in 18888e0 Feb 9, 2020
@github-actions
Copy link

github-actions bot commented Feb 8, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants