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 · 11 comments
Closed

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

Brixy opened this issue Feb 4, 2020 · 11 comments
Labels
Bug
Milestone

Comments

@Brixy
Copy link

@Brixy 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

This comment has been minimized.

Copy link
Member

@bep 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

This comment has been minimized.

Copy link
Author

@Brixy 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 Feb 4, 2020
@bep

This comment has been minimized.

Copy link
Member

@bep 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

This comment has been minimized.

Copy link
Author

@Brixy 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

This comment has been minimized.

Copy link
Member

@bep bep commented Feb 4, 2020

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

@Brixy

This comment has been minimized.

Copy link
Author

@Brixy 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

This comment has been minimized.

Copy link
Author

@Brixy 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

This comment has been minimized.

Copy link

@hbarthel 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

This comment has been minimized.

Copy link

@serg 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

This comment has been minimized.

Copy link
Contributor

@onedrawingperday 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

This comment has been minimized.

Copy link
Member

@bep 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
Introduced in Hugo 0.64.0

Fixes gohugoio#6851
bep added a commit to bep/hugo that referenced this issue Feb 9, 2020
Introduced in Hugo 0.64.0

Fixes gohugoio#6851
@bep bep closed this in 18888e0 Feb 9, 2020
@fmotrifork fmotrifork mentioned this issue Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.