Resource.Copy creates URL-encoded filename

Hugo 0.111 and 0.115
Passing the name Blüte.webp to Resource.Copy creates a file Bl%C3%BCte.webp (on macOS, but I guess it works the same on other platforms). The Permalink of this file is http://... Bl%C3%BCte.webp. Which the browser tries to load the file, it converts this to http://... Blüte.webp.

But obviously, there is no file Blüte.webp, since Resource.Copy URL-encoded the umlaut. Non-ASCII characters in filenames are ok now on the web, and there are quite some languages that rely on them. My file system supports them, my browser does (and it does the necessary URL conversion, too).

Is that the intended behavior? If so – why? If not, maybe it should be fixed.

Yes, there is.

With this template code:

{{ with resources.GetMatch "hügo.jpg" }}
  {{ with .Resize "200x webp" }}
    {{ with resources.Copy "Blüte.webp" . }}
      <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
      <p><a href="{{ .Permalink }}">Link to image</a></p>
    {{ end }}
  {{ end }}
{{ end }}

The published site has this structure:

public/
├── posts/
│   ├── post-1/
│   │   └── index.html
│   └── index.html
├── Blüte.webp
└── index.html

The page looks like:

image

And when you click “Link to image” you see this (notice the address bar):

image

So I’m not sure where the problem is. Try it:

git clone --single-branch -b hugo-forum-topic-45092 https://github.com/jmooring/hugo-testing hugo-forum-topic-45092
cd hugo-forum-topic-45092
hugo server

Thanks for taking the time to look into that. My use case is a bit more complicated, and it looks like this:

 {{ $imgJPG := resources.GetMatch "blüte.jpg"}}
 {{ $imgBase := replaceRE "([^.]*)\\.(jpg|png)$" "$1" $imgJPG.Key }}
 {{ $webp := $imgJPG.Resize (printf "%dx%d webp" $imgJPG.Width $imgJPG.Height)  | resources.Copy (printf "%s.webp" $imgBase) }}
        <img src="{{ $webp.RelPermalink }}" width="{{ $webp.Width }}" height="{{ $webp.Height }}" alt="">
        <p><a href="{{ $webp.Permalink }}">Link to image</a></p>

Main differences to your test case:

  • The original file contains an “ü” (or any other non-ASCII character, afaict)
  • I get the resource with this file and use its Key to obtain the full path

Which, as it turns out, is the problem here. Key does the conversion to URL-encoded, and I do not even need it – Name works just fine, since Resources.Copy apparently copies into the “current directory” (or whatever is the correct term here – not that the documentation says anything about it).

So, replacing Key with Name in my code made everything behave as it should. Thanks again.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.