Support a :sectionslug permalink token

The URL path elements in a published Hugo site typically mirror the directory and file names of the content hierarchy within the content/ directory, however, this is not always desirable. There are legitimate reasons for wanting these structures to differ.

It is easy to modify the final filename element of the URL using the slug front matter parameter but it is not possible to modify the naming of individual sections in a similar way.

We propose adding a :sectionslug permalink token (similar in priniciple to the existing :sections token) that modifies a section’s URL path element by using the slug or title parameters as defined in a section’s front matter (in _index.md file) iteratively to create the URL path, resulting in a slugified path

NOTE: The url field in the front matter can currently be used to override the entire path. This approach becomes error prone when handling nested content section hierarchies as care must be taken to propagate any changes to a section’s url to its subsections.

Example

Given the content structure:

content/                           
└── 01-parent-section/
     ├── _index.md   # slug: my-parent-section-slug ; title: "My Parent Section Title"
     ├── 01-article.md			
     └── 02-child-section/
         ├── _index.md   # title: "My Child Section"
         └── 01-nested-article.md # title: "My Nested Article"

And the following permalink configuration using the proposed :sectionslug token:

# config.yaml
...
permalinks:
  page: 
    01-parent-section: /:sectionslug/:slug
  section:
	01-parent-section: /:sectionslug/:slug

The published site structure would be:

public/                           
└── my-parent-section-slug/
   ├── index.html   
   └── my-child-section/ 
       ├── index.html
       └── my-nested-article/ 
           └── index.html

We have already written and tested the code for this on multiple Hugo sites, and can make it available on request.

I haven’t thought this through… it sounds like you have. Can you think of any scenarios where you wouldn’t want this behavior? I’m not suggesting changing the current behavior… just thinking out loud.

Also, wouldn’t we want symmetry?

Existing New
:section :sectionslug
:sections :sectionsslug (not a great name, maybe sectionslugs instead)

I like your recommendation on symmetry, makes its more cleaner. I prefer sectionslugs over sectionsslug. It’s easy to read and say :slight_smile:

I cannot think of any scenarios where you wouldn’t want this behavior while explicitly adding the permalink token to your config file.

The only implication I can see implementing this, is a possible performance hit on very very deep hierarchies.

This is a good idea. Please create a proposal and cross reference this forum topic. Thanks.

Thanks for the feedback, I’ll get onto the proposal.