Skip to content

Conversation

@bep
Copy link
Member

@bep bep commented Feb 15, 2025

  • 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

@bep bep force-pushed the feat/contentbasename branch 2 times, most recently from 0cc9cfa to 76d7510 Compare February 15, 2025 10:35
* 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
@bep bep force-pushed the feat/contentbasename branch from 76d7510 to f6050db Compare February 15, 2025 10:46
@bep bep marked this pull request as ready for review February 15, 2025 15:19
@bep bep requested a review from jmooring February 15, 2025 15:19
@bep
Copy link
Member Author

bep commented Feb 16, 2025

@jmooring I would appreciate if you could have a quick look at this/take it for a spin. My last take on this makes these new tokens also work with content adapters and pages not backed by any file. I don't see any "catch", but I have said that before and been wrong, so It would be great with a second set of eyes.

@jmooring
Copy link
Member

Yeah, this is on my list for today, but there's some life I have to take care of first :)

@jmooring
Copy link
Member

jmooring commented Feb 17, 2025

This works perfectly. Tested with page kinds:

  • page (leaf bundle)
  • page (not leaf bundle)
  • section (backed by file)
  • section (not backed by file)
  • term (backed by file)
  • term (not backed by file)
  • taxonomy (backed by file)
  • taxonomy (not backed by file)
  • page, section, term, and taxonomy from a content adapter

My only comment: I can't think of a reason for using the :filename or :slugorfilename permalink tokens ever again... so I'm inclined to deprecate them.

If you agree you can place this in config/allconfig/allconfig.go around line 430. I've tested it. Or I can submit a separate PR. Or do nothing.

// Legacy permalink tokens
vs := fmt.Sprintf("%v", c.Permalinks)
if strings.Contains(vs, ":filename") {
	hugo.Deprecate("the \":filename\" permalink token", "Use \":contentbasename\" instead.", "0.144.0")
}
if strings.Contains(vs, ":slugorfilename") {
	hugo.Deprecate("the \":slugorfilename\" permalink token", "Use \":slugorcontentbasename\" instead.", "0.144.0")
}
@bep
Copy link
Member Author

bep commented Feb 17, 2025

Or I can submit a separate PR. Or do nothing.

Please do that. Doing it as a "separate thing" makes it more visible. If you don't find time, I will put it on my TODO list.

Thanks for the testing of this PR, much appreciated.

@bep bep merged commit 7b7a0f3 into gohugoio:master Feb 17, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants