I have a photo/image for the post in $resource
variable. In my use case it’s located in filesystem with some timestamp-like name and I’d like to rename it during Hugo processing. My wish is to have this working: {{< img "2024-12-31_09.13.00.jpg" "human-readable-name.jpg" >}}
.
I have some shortcode which, among other stuff, does something like this:
{{ $thumbname2 := printf "%s/%s%s" (path.Dir $resource.RelPermalink) "thumb_123" (path.Ext $resource.RelPermalink) }}
{{ $zz := $resource | resources.Copy $thumbname2 }}
<br>{{$zz.Permalink}} - <img src="{{ $zz.Permalink }}" alt="{{ $zz.Permalink }}" />
My expectation is that new file containing thumb_123
should appear on the filesystem and should be accessible (like, the img tag should show it).
However, it does not work! It only works if I explicitly modify the image like this (note Resize
on the second line)
{{ $thumbname2 := printf "%s/%s%s" (path.Dir $resource.RelPermalink) "thumb_123" (path.Ext $resource.RelPermalink) }}
{{ $zz := $resource.Resize "300x" | resources.Copy $thumbname2 }}
<br>{{$zz.Permalink}} - <img src="{{ $zz.Permalink }}" alt="{{ $zz.Permalink }}" />
Is this expected behavior? Am I doing something wrong? How can I rename existing resource without modifying it?