Skip to content

Conversation

@dvdksn
Copy link
Contributor

@dvdksn dvdksn commented Nov 10, 2025

Summary

This PR fixes the slugorcontentbasename permalink token creating an extra subdirectory for section pages (_index.md files).

Problem

When using slugorcontentbasename in permalinks for section pages, an extra subdirectory was created. For example:

permalinks:
  section:
    foo: /:sections[1:]/:slugorcontentbasename/

With content at content/foo/bar/_index.md, this would generate /bar/bar/index.html instead of the expected /bar/index.html.

The deprecated slugorfilename token worked correctly by returning an empty string for _index.md files.

Solution

Added special handling in pageToPermalinkContentBaseName to return an empty string for section pages (_index.md files), matching the behavior of pageToPermalinkFilename.

Testing

  • Added integration test TestIssue14104 to verify the fix
  • All existing tests pass
  • Tested with the reproduction repository from the issue

🤖 Generated with Claude Code

Fixes #14104

// pageToPermalinkContentBaseName returns the URL-safe form of the content base name.
func (l PermalinkExpander) pageToPermalinkContentBaseName(p Page, _ string) (string, error) {
// For section pages (_index.md), return empty string to match the behavior of pageToPermalinkFilename
if l.translationBaseName(p) == "_index" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can do p.PathInto().IsBranchBundle and get a slightly cleaner setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated to use p.PathInfo().IsBranchBundle() along with p.File() != nil to handle sections without files

The slugorcontentbasename permalink token was creating an extra
subdirectory for section pages (_index.md files). This was because
pageToPermalinkContentBaseName did not have the same special handling
for _index.md files as pageToPermalinkFilename.

This commit adds the special handling to return an empty string for
section pages, ensuring backward compatibility with slugorfilename.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Fixes gohugoio#14104
@dvdksn dvdksn force-pushed the fix-slugorcontentbasename-section-pages branch from 650099b to c483799 Compare November 10, 2025 11:52
@bep bep merged commit 25c7c18 into gohugoio:master Nov 10, 2025
6 checks passed
@dvdksn dvdksn deleted the fix-slugorcontentbasename-section-pages branch November 10, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants