Skip to content

Implement a :sectionslug and a :sectionslugs permalink token #13788

Open
@torabisu

Description

@torabisu

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 :sectionslug and :sectionslugs permalink tokens (in symmetry to the existing :section and :sections tokens) 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). :sectionslugs will traverse the hierarchy 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 :sectionslugs

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 :sectionslugs token:

# config.yaml
...
permalinks:
  page: 
    01-parent-section: /:sectionslugs/:slug
  section:
	01-parent-section: /:sectionslugs/: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.

See the forum discussion here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions