How decode URLs in Hugo?


How I can decode URLs in Hugo?


See Hugo Template Functions

Don’t know what you’re trying to do but have a look at replace replacere htmlUnescape safeHTML etc.

Actually I read them before posting here, thanks for your answer anyway.

I need some method/helper that do tha same job as decodeURI in JavaScript

If you use a taxonomy, and term’s value is an East Asia word, such as Chinese, the .URL will looks like %E6%B3%A2%E9%9F%B3.
HtmlUnescape can’t solved this problem.

And I also want to know how to do, if I want to get the original text from .URL?

Hi there, I just found a trick for that:

{{ $url := urls.Parse ($tag | urlize) }}
{{ $path := $url.Path }}
{{ with $.Site.GetPage (printf "/tags/%s" $path) }}
# See

In this way, you can still get the page even if the name of the tag is SSG (Static Site Generator) or Raspberry Pi(树莓派).


1 Like