Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags containing '#' produce invalid links #197

Open
thomaslevesque opened this issue May 3, 2020 · 7 comments
Open

Tags containing '#' produce invalid links #197

thomaslevesque opened this issue May 3, 2020 · 7 comments

Comments

@thomaslevesque
Copy link
Contributor

thomaslevesque commented May 3, 2020

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

@thomaslevesque thomaslevesque changed the title Tags containing '#' produce invalid links in tag list widget Tags containing '#' produce invalid links May 3, 2020
@thomaslevesque
Copy link
Contributor Author

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

@thomaslevesque
Copy link
Contributor Author

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.

@Vimux
Copy link
Owner

Vimux commented May 3, 2020

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.

@thomaslevesque
Copy link
Contributor Author

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

@Vimux
Copy link
Owner

Vimux commented May 3, 2020

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.

@thomaslevesque
Copy link
Contributor Author

@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.

@Vimux Vimux reopened this May 3, 2020
@Vimux
Copy link
Owner

Vimux commented May 3, 2020

@thomaslevesque,

Thank you, but I re-opened this issue. I think other people may face the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants