-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Add permalinks tokens contentbasename and contentbasenameorslug #11722
Comments
Both filenames are _index.md. Not sure why you would want to do this. Seems like you want this instead:
|
@jmooring for other files,
And the post at
If it works for posts, why doesn't it work for categories? I want the name attributed to that entry. Whether it is a directory entry of just a markdown file, it should not matter. You can see the source here: https://github.com/hacdias/hacdias.com I wanted the categories to also use the disk name without me having to define a manual slug and not be dependent on the title, just like the posts. |
Assuming you have files backing these categories, I don't see how they should behave differently. But I see this in your config, which does not match your expectations: [permalinks]
tags = '/tags/:title/'
categories = '/:title/'
posts = '/:year/:month/:day/:filename/' Also, I suspect that |
I want to change to |
hugo/resources/page/permalinks.go Lines 265 to 277 in 68e9532
Examining the above, the To avoid a breaking change, I suggest that we add a
|
That's interesting and looks like the source of the problem. I'm not sure that introducing Whatever is done, I think the documentation should be clarified: https://gohugo.io/content-management/urls/#tokens |
Other considerations... In most cases taxonomy terms are not backed by a file, so should
We have a |
While updating https://gohugo.io/content-management/urls/#tokens to match current behavior, adding exceptions to the documentation is clumsy and a bit convoluted (e.g., "This applies to xxx but not to yyy."). I think we should:
@bep I would appreciate it if you would (a) close this as "won't fix", (b) reclassify it as enhancement, or (c) comment with recommended changes. Thanks. I'm pretty sure the current token implementation predates the |
Changed categories to work with slugs instead. Otherwise it wouldn't be possible to just rename the category without changing the permalink. See gohugoio/hugo#11722
Hi! Is there a plan to address this? I just made a PR for it: #13382 |
@hacdias This issue is still a proposal (see labels). If the project lead accepts the proposal the label will change to "enhancement". At that point PRs will be welcome. |
Is this intentional or should it be switched? ( |
OK, here is what I suggest we do. This is the current logic in #13382: // pageToPermalinkContentBaseName returns the URL-safe form of the content base name.
func (l PermalinkExpander) pageToPermalinkContentBaseName(p Page, _ string) (string, error) {
if p.File() == nil {
return "", nil
}
return l.urlize(p.File().ContentBaseName()), nil
}
// pageToPermalinkContentBaseNameOrSlug returns the URL-safe form of the content base name, or the slug.
func (l PermalinkExpander) pageToPermalinkContentBaseNameOrSlug(p Page, a string) (string, error) {
name, err := l.pageToPermalinkContentBaseName(p, a)
if err != nil {
return "", nil
}
if name != "" {
return name, nil
}
return l.pageToPermalinkSlugElseTitle(p, a)
} I suggest that for
For
This way we're 1) Mostly compatible with what we have and 2) People can have their |
Sorry for the delay. This sounds right to me, but I would like to take the PR for a spin to be sure. |
@jmooring I just pushed and updated PR. I plan on doing a Hugo release Monday evening (Norway time). |
This works great. |
It sounds like a good idea to make it |
* Make it work for all pages, including those created from content adapters and not backed by a file. * Allow the `slug` to win, so the new tokens are: `:contentbasename`: 1. ContentBaseName `:slugorcontentbasename`: 1. Slug 2. ContentBaseName Note that a page will always have a `ContentBaseName`, so no need to fall back to e.g. the title. Closes gohugoio#11722
* Make it work for all pages, including those created from content adapters and not backed by a file. * Allow the `slug` to win, so the new tokens are: `:contentbasename`: 1. ContentBaseName `:slugorcontentbasename`: 1. Slug 2. ContentBaseName Note that a page will always have a `ContentBaseName`, so no need to fall back to e.g. the title. Closes gohugoio#11722
* Make it work for all pages, including those created from content adapters and not backed by a file. * Allow the `slug` to win, so the new tokens are: `:contentbasename`: 1. ContentBaseName `:slugorcontentbasename`: 1. Slug 2. ContentBaseName Note that a page will always have a `ContentBaseName`, so no need to fall back to e.g. the title. Closes gohugoio#11722
* Make it work for all pages, including those created from content adapters and not backed by a file. * Allow the `slug` to win, so the new tokens are: `:contentbasename`: 1. ContentBaseName `:slugorcontentbasename`: 1. Slug 2. ContentBaseName Note that a page will always have a `ContentBaseName`, so no need to fall back to e.g. the title. Closes #11722
What version of Hugo are you using (
hugo version
)?Does this issue reproduce with the latest release?
categories
taxonomy./categories/a/_index.md
and/categories/b/_index.md
All categories will be concurrently built to
/index.html
, which leads me to believe that:filename
is empty for them.The text was updated successfully, but these errors were encountered: