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

Global resource isn't published when using an uncommon code construct #12190

Closed
adityatelange opened this issue Mar 1, 2024 · 11 comments
Closed

Comments

@adityatelange
Copy link

adityatelange commented Mar 1, 2024

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

$ hugo version
hugo v0.123.7-312735366b20d64bd61bff8627f593749f86c964 linux/amd64 BuildDate=2024-03-01T16:16:06Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

Steps to reproduce

  1. Clone PaperMod's exampleSite https://github.com/adityatelange/hugo-PaperMod/tree/exampleSite
  2. Build with hugo
  3. Observe that public directory does not contain images.

Images are linked on this page https://github.com/adityatelange/hugo-PaperMod/blob/4bdc993b98cc82d1c59efca0774f85811b0bf213/content/posts/papermod/papermod-installation.md?plain=1#L10-L12

@adityatelange
Copy link
Author

adityatelange commented Mar 1, 2024

Another issue site.Home.AllTranslations behaves differently with 0.123.0 and above. No issues with 0.122.0

makes a conflict with https://github.com/adityatelange/hugo-PaperMod/blob/55b2eb48ff90f086c300e9e33632465e919e2794/layouts/partials/header.html#L100-L103

@jmooring
Copy link
Member

jmooring commented Mar 1, 2024

Without digging into this too much...

1) When I build the example site with v0.122.0, I see:

public/assets/
├── css/
│   └── stylesheet.0ede93e9169d0d059603a3eb4a3ecfb1dde2b3ad9f49b4079fc9b78c1a042d13.css
└── js/
    └── search.6414a722d5dffb9b3a958f0cbefccac6b7a82cb0beaa6c759d0d473bb6c7e7cc.js

There are no images in the above, so this doesn't appear to be anything new.

2) Why should the images be published to the assets directory?

@adityatelange
Copy link
Author

adityatelange commented Mar 1, 2024

Without digging into this too much...

  1. When I build the example site with v0.122.0, I see:
public/assets/
├── css/
│   └── stylesheet.0ede93e9169d0d059603a3eb4a3ecfb1dde2b3ad9f49b4079fc9b78c1a042d13.css
└── js/
    └── search.6414a722d5dffb9b3a958f0cbefccac6b7a82cb0beaa6c759d0d473bb6c7e7cc.js

There are no images in the above, so this doesn't appear to be anything new.

  1. Why should the images be published to the assets directory?
  1. My bad they go to public/images instead of public/assets. with 0.123.0 they don't.

  2. To use it as a global resource https://gohugo.io/content-management/image-processing/#global-resource

@jmooring
Copy link
Member

jmooring commented Mar 1, 2024

To reproduce:

git clone https://github.com/adityatelange/hugo-PaperMod
cd hugo-PaperMod
git checkout exampleSite
git submodule update --init --recursive
rm -rf public && hugo && tree public/images

This worked in v0.122.0, and stopped working in v0.123.0 through v0.123.7.

@jmooring
Copy link
Member

jmooring commented Mar 1, 2024

@adityatelange

Another issue site.Home.AllTranslations behaves differently

If it's another issue, open another issue.

@jmooring
Copy link
Member

jmooring commented Mar 1, 2024

Here's the change in behavior...

Content

content/
└── _index.md

Template (layouts/index.html)

I have never seen or used this construct before; not sure if it was ever supposed to work.

{{ with resources.ByType "text" }}
  {{ with .Get "a.txt" }}
    {{ .Publish }}
  {{ end }}
{{ end }}

You'll get the same result when replacing .Get above with .GetMatch.

Expected (v0.122.0)

public/
├── a.txt
└── index.html

Actual (v0.123.7)

public/
└── index.html

Test case

failing test case
func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- assets/a.txt --
I am a.txt
-- assets/b.txt --
I am b.txt
-- layouts/index.html --
{{ with resources.ByType "text" }}
  {{ with .Get "a.txt" }}
    {{ .Publish }}
  {{ end }}
  {{ with .GetMatch "*b*" }}
    {{ .Publish }}
  {{ end }}
{{ end }}
`

	b := hugolib.Test(t, files)

	b.AssertFileExists("public/index.html", true)
	b.AssertFileExists("public/a.txt", true) // failing test
	b.AssertFileExists("public/b.txt", true) // failing test
}

@jmooring jmooring changed the title Images in assets directory are not processed Global resource isn't published when using an uncommon/questionable code construct Mar 1, 2024
@adityatelange
Copy link
Author

@jmooring I don't understand why this is being highlighted as uncommon/questionable code construct?

Global resources are useful and are required when you intend to use a single image with all pages. For example processing images to watermark your images or apply some filter on all of them (read https://adityatelange.in/blog/hugo-watermarking-images/#the-code-snippet-).

@jmooring
Copy link
Member

jmooring commented Mar 3, 2024

Global resources are useful and are required

I understand that, but I have never seen the construct where the .Get/.GetMatch/.Match/.ByType methods are used with a slice created from global resources. And obviously there's not an existing test for this.

I don't have a problem with the construct; I like the parallelism:

{{ with resources.ByType "text" }}
  {{ with .Get "a.txt" }}
    {{ .Publish }}
  {{ end }}
{{ end }}

{{ with .Resources.ByType "text" }}
  {{ with .Get "c.txt" }}
    {{ .Publish }}
  {{ end }}
{{ end }}

@jmooring jmooring changed the title Global resource isn't published when using an uncommon/questionable code construct Global resource isn't published when using an uncommon code construct Mar 3, 2024
@bep bep self-assigned this Mar 7, 2024
@bep bep added this to the v0.123.8 milestone Mar 7, 2024
bep added a commit to bep/hugo that referenced this issue Mar 7, 2024
bep added a commit to bep/hugo that referenced this issue Mar 7, 2024
@bep bep closed this as completed in 4d5e173 Mar 7, 2024
bep added a commit that referenced this issue Mar 7, 2024
@adityatelange
Copy link
Author

@jmooring
Copy link
Member

jmooring commented Mar 7, 2024

@adityatelange We fixed this issue, but it looks like there's a matching problem now. See #12214.

FYI, commenting on a closed issue isn't the best approach. Frequently such comments are ignored because... the issue is closed.

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 29, 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