Mainroad
Mainroad copied to clipboard
Tags containing '#' produce invalid links
For instance, the tag C# produces the URL /tags/c#/, which yields a 404. The correct URL is /tags/c%23/.
~~The problem only exists in the widget, not on the posts themselves.~~ Scratch that, actually it's also on the posts, but the problem is different. See next message for details
Related to this thread: https://discourse.gohugo.io/t/special-characters-in-tags/6410/4
In fact, the problem is also in posts, but slightly different.
- In the tag list widget, the
C#tag links to/tags/c#(invalid) - In the post tags, the
C#tag links to/tags/c(also invalid)
I think # in tag names needs to be manually replaced by %23
The problem is also on the tag page: the link to the next page is broken, for the same reason. Not sure how to fix this one, though... I don't really know how the paginator works.
Upstream bug (limitation). As far as I remember, special characters are still an unresolved thing for Hugo taxonomies (tags, categories, ...). All related examples/functions in the Hugo documentation do not handle such cases (with special URI/URL characters). Or they can handle this case, but break anything else.
All other options like "use replace" are suitable for a specific site, but not for the theme, I think.
Yeah, I agree this should be properly handled by Hugo itself, it shouldn't be the theme's responsibility. I guess Hugo should just expose the URL of the tag page
Anyway, the replace workaround works for me in the post tags and tag list widget, but I'm not sure how to fix the paginator... Not a major issue, but it's annoying
Anyway, the replace workaround works for me in the post tags and tag list widget, but I'm not sure how to fix the paginator...
/tags/c#/page/2/, /tags/c#/page/3/, ...?
Technically, the same way.
paginator.html:
{{- if or (.Paginator.HasPrev) (.Paginator.HasNext) }}
<div class="pagination">
{{- if .Paginator.HasPrev }}
<a class="pagination__item pagination__item--prev btn" href="{{ replace .Paginator.Prev.URL "#" "%23" }}">«</a>
{{- end }}
<span class="pagination__item pagination__item--current">
{{- .Paginator.PageNumber }}/{{ .Paginator.TotalPages -}}
</span>
{{- if .Paginator.HasNext }}
<a class="pagination__item pagination__item--next btn" href="{{ replace .Paginator.Next.URL "#" "%23" }}">»</a>
{{- end }}
</div>
{{- end }}
Not tested.
@Vimux thanks! Actually I was looking for a way to do the replace on the tag name only, rather than the whole URL, but I guess it should work as well.
Closing, since the issue is in Hugo, not in the theme.
Great work on this theme, by the way, I love it! Great level of customization.
@thomaslevesque,
Thank you, but I re-opened this issue. I think other people may face the same problem.