Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add a more flexible filename identifier scheme that also allows setting roles and versions #14750

@bep

Description

@bep

Hugo currently supports encoding some options in filenames, e.g.:

  • mypage.en.md — content file with language set.
  • list.en.rss.html — layout file with both language and output format set.

But the above does not allow us to set role or version, as that would lead to ambiguity.

Wrapper syntax

Hugo already supports a wrapper syntax using underscores for custom identifiers in content filenames, e.g. mypage._myidentifier_.md. The wrapped segment is treated as an opaque block by the filename parser, which means dots and other characters inside it are not interpreted as segment delimiters. The identifier itself is currently ignored, but it allows multiple content files to share the same logical name while defining different sites in front matter.

Prefix identifiers

This proposal builds on the wrapper syntax by giving the wrapped segments a structured meaning through prefix identifiers. For example, mypage._language_en_.md would set the language to en. Multiple identifiers can be combined, e.g.:

mypage._language_en_._role_admin_.md

For identifiers that support multiple values, the same prefix can be repeated:

mypage._role_guest_._role_admin_.md

The wrapper syntax also allows values that contain dots, which would otherwise be ambiguous:

mypage._version_v1.0.0_._language_en_.md
Prefix Description Relevant for
language_ Language Content and layout files.
role_ Role Content and layout files.
version_ Version Content and layout files.
outputformat_ Output format Layout files.
mediatype_ Media type Layout files.
kind_ Page kind Layout files.
layout_ Layout Layout files.

The existing mypage.en.md format would still be supported.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions