gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
74.8k stars 7.46k forks source link

Broken taxonomy list in a single page template because of some characters #6546

Closed Vimux closed 4 years ago

Vimux commented 4 years ago

Briefly

Tag list (or any other taxonomy list) in a single page don't show some page tags because of urlized characters.

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.60.0-F2DEA9B0 darwin/amd64 BuildDate: 2019-11-27T10:09:53Z

Other tested versions:

Hugo Static Site Generator v0.54.0-B1A82C61 darwin/amd64 BuildDate: 2019-02-01T09:40:48Z
Hugo Static Site Generator v0.48 darwin/amd64 BuildDate: 2018-08-29T06:33:08Z

Reproduction steps

  1. Use current Example: List Tags in a Single Page Template as a tag list template:
{{ $taxo := "tags" }}
<ul id="{{ $taxo }}">
    {{ range .Param $taxo }}
        {{ $name := . }}
        {{ with $.Site.GetPage (printf "/%s/%s" $taxo ($name | urlize)) }}
            <li><a href="{{ .Permalink }}">{{ $name }}</a></li>
        {{ end }}
    {{ end }}
</ul>
  1. Add tag "Révolution française" to any post:
tags:
  - "Révolution française"

Actual results:

Empty tag list.

Expected results:

Tag list with a clickable tag.

Additional notes:

This is happens because .GetPage function assume to get string like:

/tags/révolution-française

But, because of urlize, we have string like:

/tags/r%C3%A9volution-fran%C3%A7aise

I have two concerns about this:

  1. This is expected .GetPage behavior?
  2. If answer is yes, then anchorize instead of urlize could solve this problem for all predicted use cases or not? It works, but maybe this can cause some potential side effects?

I don't know it's a .GetPage or Hugo Docs problem, anyway, this needs some action or clarification.

reuixiy commented 4 years ago

My temporary workaround is to use urls.Parse to decode URLs, then you can get the page...

{{ $taxo := "tags" }}
<ul id="{{ $taxo }}">
    {{ range .Param $taxo }}
        {{ $name := . }}
        {{ $url := urls.Parse ($name | urlize) }}
        {{ $path := $url.Path }}
        {{ with $.Site.GetPage (printf "/%s/%s" $taxo $path) }}
            <li><a href="{{ .Permalink }}">{{ $name }}</a></li>
        {{ end }}
    {{ end }}
</ul>

BTW, you won't have this problem if you use .Site.Taxonomies.tags or .Data.Terms...

See also:

  1. https://discourse.gohugo.io/t/how-decode-urls-in-hugo/7549/6
  2. https://github.com/reuixiy/hugo-theme-meme/blob/master/layouts/partials/post-tags.html
  3. https://github.com/reuixiy/hugo-theme-meme/blob/master/layouts/partials/tag-cloud.html
  4. https://github.com/reuixiy/hugo-theme-meme/blob/master/layouts/partials/taxonomy.html
Vimux commented 4 years ago

@reuixiy,

Thank you. Good suggestion. I think about anchorize as an urlize replacement in this particular case. I'm still not sure that this will work for all possible cases.

BTW, you won't have this problem if you use .Site.Taxonomies.tags or .Data.Terms...

And this is the main reason why I created the issue here. I'm not a hundred percent sure that this is just Docs problem and I want to get some clarification about this. However, it doesn't negate the fact that Hugo Docs contains mislead section about very popular thing right now.


It seems I'm not the only one who thought about this:

https://github.com/gohugoio/hugoDocs/commit/7cff379f58168066073044d5a4488cc589815ae8#r33705430

reuixiy commented 4 years ago

Also note that anchorize is different from urlize, e.g.

foo(bar) | anchorize   ->   foo-bar
foo(bar) | urlize      ->   foobar
gcushen commented 4 years ago

Duplicate of #5687?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open. If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

github-actions[bot] commented 2 years ago

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.