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

resources.Match seems to be renaming files with spaces, and making the resource nil #12081

Closed
BrianLeishman opened this issue Feb 20, 2024 · 5 comments

Comments

@BrianLeishman
Copy link

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.123.0+extended linux/amd64 BuildDate=unknown

Does this issue reproduce with the latest release?

Yes

Steps to recreate

hugo new site hugo-resource-rename
cd hugo-resource-rename
hugo new theme test
hugo new content hello.md

Then I added a shortcode

resources.html

{{ range resources.Match `*` }}
    {{ .src }}
{{ end }}

referenced the shortcode

hello.md

+++
title = 'Hello'
date = 2024-02-20T10:06:32-05:00
+++

Hello, World!

{{< resources >}}

Then added a "test doc.txt" in the assets folder, and I get this error

render: failed to render pages: render of "page" failed: �[1;36m"/home/brian/hugo-resource-rename/themes/test/layouts/_default/single.html:8:5"�[0m: execute of template failed at <.Content>: error calling Content: �[1;36m"/home/brian/hugo-resource-rename/content/hello.md:8:1"�[0m: failed to render shortcode "resources": failed to process shortcode: �[1;36m"/home/brian/hugo-resource-rename/layouts/shortcodes/resources.html:2:7"�[0m: execute of template failed at <.src>: can’t evaluate field src in type resource.Resource

If I change {{ .src }} to {{ . }} in my partial, I see this output

Hello, World!
/test-doc.txt 

Where it appears to be adding a dash that wasn't there to begin with. If I remove the space myself it works as expected.

@bep
Copy link
Member

bep commented Feb 20, 2024

Fixed in #12076

@bep bep closed this as completed Feb 20, 2024
@BrianLeishman
Copy link
Author

@bep I think that commit is part of the v0.123.1 release, but this issue is unchanged

$ hugo version
hugo v0.123.1+extended linux/amd64 BuildDate=unknown

Error: error building site: render: failed to render pages: render of "page" failed: "/home/brian/hugo-resource-rename/themes/test/layouts/_default/single.html:8:5": execute of template failed: template: _default/single.html:8:5: executing "main" at <.Content>: error calling Content: "/home/brian/hugo-resource-rename/content/hello.md:8:1": failed to render shortcode "resources": failed to process shortcode: "/home/brian/hugo-resource-rename/layouts/shortcodes/resources.html:2:7": execute of template failed: template: shortcodes/resources.html:2:7: executing "shortcodes/resources.html" at <.src>: can't evaluate field src in type resource.Resource

{{ range resources.Match `*` }}
    {{ .src }}
{{ end }}

@jmooring
Copy link
Member

@BrianLeishman

{{ range resources.Match `*` }}
  {{ .src }}
{{ end }}

In this context, .src isn't a thing.

Not sure what you're trying to do. Maybe you want this:

{{ range resources.Match `*` }}
  {{ .Content }}
{{ end }}

These are the available methods on a Resource object:
https://gohugo.io/methods/resource/

.src isn't one of them.

This issue is closed. If you need further assistance, please create a new topic on the forum. Thanks.

@BrianLeishman
Copy link
Author

Ah true, duh, my bad! The files in our real source were images

Copy link

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 Mar 14, 2024
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

3 participants