-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
This document provides an overview of the new features, terms, and API changes in this version.
New and Changed API
Page.Rotate("language"|"version"|"role"): Returns a list of pages for the given dimension, holding the other two dimensions constant.Site.Dimension("language"|"version"|"role"): Returns the current dimension object (Language,Version, orRole).{language|version|role}.IsDefault: Returns true if the given dimension object is the default.{language|version|role}.Name: Returns the name of the dimension object (e.g., "en", "v2.0.0", "guest"). This is the lower cased key used in the configuration.
New Concepts
- 3D Build Matrix: Content can now be built for a three-dimensional matrix of Languages, Versions, and Roles.
- Sites Matrix: Defines what sites content should be built for.
- Sites Complements: Defines what sites content should complement.
- Site Vector: Internally, each unique Site is identified by a vector (e.g.,
{0,0,0}), which represents a specific combination of language, version, and role.
Sites Matrix and Complements
The sites.matrix and sites.complements can be configured in:
-
File mounts (currently relevant for content and layouts mounts).
-
Content front matter.
-
Site and content cascade configuration.
-
For
content:sites.matrixbuilds the content to every combination of matching languages, versions and roles.sites.complementscomplements, fills in any gaps of missing content, in sites matching the configured languages, versions and roles. This will not create new URLs.- When selecting a complement candidate, Hugo prefers closer matches. For equally close matches, it prioritizes the one that appears first in the sorted dimension configuration. For example, if languages are ordered
no,sv,da, and content is configured to complementda, asvmatch will be chosen over anomatch because it is "closer" in the list.
-
For
layouts:sites.matrixdetermines which template is used to render a piece of content.sites.complementsis not currently relevant for layouts.
Precedence and Filtering:
- Configuration in front matter has higher precedence than in file mounts.
- File mounts with a
sites.matrixcontaining Glob patterns that don't match any active sites will be skipped. sites.matrixcan also be used as a filter in segments (https://gohugo.io/configuration/segments/#segment-definition).- When using cascade, the
sites.matrixis applied in steps: first, cascades without asites.matrixfilter are applied; second, the
sites.matrixis built; finally, cascades with asites.matrixfilter are applied, and the matrix is rebuilt if it changed.
Sites Matrix and Filenames
- For content and layout files, it's still possible to add one language identifier to the filename, e.g.
/content/mypost.en.mdor/layouts/home.en.html - You can now also create custom, shared identifiers for content files by wrapping the identifier in underscores. For example,
mypost._scandinavian_.mdcan be used to associate that file with a customsites.matrixdefinition (see issue Add custom identifier prefix in content filenames #14001).
Content Adapters
Before this version, a _content.gotmpl file was executed once for the Site that matched its language. You could invoke .EnableAllLanguages to execute the template for all sites.
Now, with a 3D matrix, a _content.gotmpl file is, by default, executed only once for the first matching Site. You can use
.EnableAllDimensions to run it for all sites. However, the recommended approach is to use the sites.matrix configuration (in the mount or front matter) to control which sites the content is generated for.
Glob Negation Prefix
Many Glob filters in Hugo now support the negation prefix "! " (an exclamation mark followed by a single space) to exclude
patterns. This is supported in:
sites.matrixandsites.complements:- languages: ["! {sv,no,nn,da}", "**"] (matches all languages except Scandinavian ones).
- File mount filtering:
- files: ["! .{html,txt}", ""] (includes all files except those with .html or .txt extensions).
- Segment filtering.
Notes
- Build Order: Hugo builds sites based on the sorted dimensions (see below). In earlier versions, we built the sites starting with the default content language. This change is also reflected in the sort order of
.Site.Sitesto make it consistent with.Site.Languages. - Sort Order: The dimensions are sorted as follows, which affects build order and complement selection:
- languages: By weight, then by name.
- versions: By weight, then by semantic versioning (descending).
- roles: By weight, then by name.
- Deprecations:
- The lang option on mounts (https://gohugo.io/configuration/module/#mounts) and segments
(https://gohugo.io/configuration/segments/#segment-definition) is deprecated in favor of the more powerfulsites.matrix
option. - File mount
includeFilesand excludeFiles` are deprecated in favor of the new files filter, which supports negation.
- The lang option on mounts (https://gohugo.io/configuration/module/#mounts) and segments
- Logging: We no longer log warnings about potential duplicate content paths, as this becomes impractical to reason about with a
complex sites matrix.