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.Copy to original resource path points to wrong resource #10412

Closed
jmooring opened this issue Nov 3, 2022 · 4 comments · Fixed by #12311
Closed

resources.Copy to original resource path points to wrong resource #10412

jmooring opened this issue Nov 3, 2022 · 4 comments · Fixed by #12311

Comments

@jmooring
Copy link
Member

jmooring commented Nov 3, 2022

assets/
└── a.jpg    # image is 600x400

This works as expected...

{{ with resources.Get "a.jpg" }}
  {{ with .Resize "200x" | resources.Copy "foo.jpg" }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
  {{ end }}
{{ end }}
<img src="/foo.jpg" width="200" height="133">

But if you try to copy the resource to the original path (a.jpg)...

{{ with resources.Get "a.jpg" }}
  {{ with .Resize "200x" | resources.Copy "a.jpg" }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}">
  {{ end }}
{{ end }}
<img src="/a.jpg" width="600" height="400">

Note that the width and height attributes are from the original image, not the resized image.

Why would you want to copy a resource to its original path? To have something other than this:

<img src="/a_hu7ea6bbdd4d289c929adf1f5f39c46d1e_158382_200x0_resize_q75_box.jpg" width="200" height="133">
@bowman2001
Copy link

bowman2001 commented Nov 3, 2022

To copy a resource to its original path is also of concern, when an image is processed more than once. In the first step, images may be resized or cropped, etc. In the second step, a "srcset" is generated, which involves again resizing or filtering. Without copying the result of the first step to the original name, Hugo’s naming scheme concatenates two hashes and other information into the resulting filenames. These names then usually get so long, that Hugo truncates them to avoid problems. The part of the filename string containing information about the last processing step is usually lost, then.

@jmooring
Copy link
Member Author

jmooring commented Nov 3, 2022

If fixing/implementing this is going to be expensive or impossible, perhaps we could disallow using the original resource path to avoid unexpected results (e.g., incorrect .Width and .Height).

@bep bep removed the NeedsTriage label Nov 4, 2022
@bep bep added this to the v0.106.0 milestone Nov 4, 2022
@bep
Copy link
Member

bep commented Nov 4, 2022

If fixing/implementing this is going to be expensive or impossible

It was certainly not intended to be used this way. The technical reason is that we use the resource path as a cache key, but even if we fix that there is a "meta question" that I cannot wrap my head around:

If I do:

{{ $a := resource.Get "a.json" }}
{{ $acopy := $a | copy "a.json" }}
{{ $a.RelPermalink }}
{{ $acopy.RelPermalink }}

What would be the RelPermalink values above? If this was the MacOS Explorer, you would maybe imagine it to append a "Copy" suffix or something to the filename. But that would most likely not be the intention in the above.

I do agree it's a bug, but the fix isn't obvious. I'm in the process of simplifying lots of related stuff now, I have this issue in the back of my head while doing so.

@bep bep modified the milestones: v0.106.0, v0.107.0 Nov 18, 2022
@bep bep modified the milestones: v0.107.0, v0.108.0 Dec 3, 2022
@bep bep modified the milestones: v0.108.0, v0.109.0 Dec 14, 2022
@bep bep modified the milestones: v0.109.0, v0.111.0 Jan 26, 2023
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@bep bep removed this from the v0.119.0 milestone Oct 5, 2023
@bep bep added this to the v0.120.0 milestone Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Mar 26, 2024
jmooring added a commit to jmooring/hugo that referenced this issue Mar 26, 2024
bep pushed a commit that referenced this issue Mar 27, 2024
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 Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants