-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Implementing path-segment sanitization rules #4092
Conversation
…y terms and titles in permalinks, so that slashes and pound signs get replaced (with hyphens) rather than considered as part of a filesystem or URL path Includes a new template function urlizeSegment (and corresponding documentation) which can be used in content to emulate said path-segment sanitization Fixes #4090
I understand the problem, but we cannot add yet another special thing with another set of special methods to handle this. Either we add this to the existing Urlize func, or we don't. I'm not sure. Will have to think about it. /cc @moorereason |
I agree with @bep. |
Thanks @bep and @moorereason for your attention on this! I agree with the sentiment of reducing special-case code paths -- that being said, the complication I ran into when beginning this work is that URL/path sanitization is applied somewhat inconsistently throughout Hugo's codebase. In some places, path segments (which should not contain a slash) are sanitized before joining them together. But in other places, the entire path (which must contain slashes) is sanitized at once. (This is not to mention the hypothetical backwards-incompatibility for templates that might currently use Phrasing the functions Would you like help with this? Per my examples, I'm somewhat invested in the cause. |
You’re correct, which is why I said I agreed with @bep’s “will have to think about it” comment. My recommendation at this point is to remove the template func stuff and just focus on fixing the internal path sanitizer issues for taxonomies and titles. Those are clear bugs. How important is the template func for your use case? |
I use the template function to implement shortcodes for linking to a specific term's page. I.e. in a post:
Then the shortcode, implemented in
Is there a better way to generate a permalink to a specific term's page? If there is, then I wouldn't have any need for urlizeSegment. |
I prefer to use “ref” and “relref” for page links. |
The This would get doubly frustrating for term hyperlinks that are generated dynamically in a layout template, such as when my layout for a post links to the term page for each game tagged in that post. The template needs both the "pretty" (for display) and sanitized (for hyperlink) forms of each term, so if there isn't a reliable way to translate one to the other, then content would need to provide both - perhaps in two separate lists? - to the template. To be clearer, what I'm looking for in a template function is a way to reference or replicate the process by which Hugo determines where a taxonomy term "lives." Then my content doesn't have to know any of the rules of this string-to-filepath translation process. What |
{{ .Site.GetPage "taxonomy" "game" "myterm" }} |
That said. Let's move the discussion to #4090. I'm closing this, as this is not the proper solution for this. |
Aha! This had escaped my notice -- using For demonstration, here's my revised shortcode template:
This does change one behavior, compared to the At least in my case, this behavior isn't a problem. Thanks @bep ! |
I think you can do something like:
But the bottom line here I think is this: The old |
This commit attempts to sanitize term keys and path segments to fix the handling of taxonomy terms containing slashes. Based upon gohugoio#4092 by @tsuereth. Fixes gohugoio#4090
This commit attempts to sanitize term keys and path segments to fix the handling of taxonomy terms containing slashes. Based upon gohugoio#4092 by @tsuereth. Fixes gohugoio#4090
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Implementing path-segment sanitization rules, for things like taxonomy terms and titles in permalinks, so that slashes and pound signs get replaced (with hyphens) rather than considered as part of a filesystem or URL path
Includes a new template function urlizeSegment (and corresponding documentation) which can be used in content to emulate said path-segment sanitization
Fixes #4090