I have two setups, 1 works and the other is causing issues.
I use this setup on page bundles, it will resize the image, rename the image and place it in the proper place. The fingerprinted file is stored in the gen folder.
when I use this same setup if the file is located in the assets directory like this:
the files are successfully created and placed in assets/avatar folder but the fingerprinted files are left over in the public folder.
I use similar method to generate different size images from page bundle resources with no issues.
When I use this for files in assets directory there fingerprinted files are also left around in the root of the public directory after building the site.
I asked about your calls to .Permalink, .RelPermalink, and .Publish because those methods cause the resource to be written to the public directory.
This works as expected
<h2>Page resource</h2>
{{ with .Resources.Get "images/a.jpg" }}
{{ with .Resize "200x" }}
{{ with . | resources.Copy "/assets/images/a.jpg" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
{{ end }}
<h2>Global resource</h2>
{{ with resources.Get "images/b.jpg" }}
{{ with .Resize "200x" }}
{{ with . | resources.Copy "/assets/images/b.jpg" }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
{{ end }}
Try it:
git clone --single-branch -b hugo-forum-topic-46552 https://github.com/jmooring/hugo-testing hugo-forum-topic-46552
cd hugo-forum-topic-46552
hugo server
First, if it were me, I wouldn’t rename the images. According to John Mueller of Google:
So having descriptive filenames is good.
But I don’t think you would see a significant change if you already do the other things around images, like the alt texts, the text surrounding the image.
Those are really, really strong signals.
And the filename itself is often… it’s kind of from a technical point of view.
This is what we called it, but it doesn’t provide any real unique information, usually.
Of course, if you don’t do the alt text, or if you don’t have good surrounding text, then, of course, the filename might be the only place where you mention what this image is about.
But if you do the rest, then usually the filenames are okay.
its really strange behavior that those functions would cause resources to be written to the public directory when they were already saved in another location and being correctly linked from that path…
trying to think of a solution, i would need to see if after the images are created, instead of linking with the *links functions, i can manually generate the file paths and link them myself. This is hacky and prone to break.
Your explanation also explains why sometimes random images would end up in the public directory but this only seems to affect resources placed in the assets directory and not page bundles.
another solution is a script that just deletes the images from the public directory after the build has been completed but again, that’s also problematic.
I was talking about webP specifically. You will be surprised how popular older iphones and macs are in some developing countries when their prices go down with age. So, as you said, it is a matter of choice vs support for your audience.
Is it possible to address the issue that I brought up? I’ve been trying different things and the more I touch resources.Copy or image processing in general, it’s pretty rough sailing.
It’s really rough just how many sharp edges are around these corners of the code.