#14842·hugo

Feature Request: Support versioning for multiple products

Author: lamATnginxCreated May 4, 2026Updated Sep 26, 2026
LabelsProposalb0

Summary

Currently Hugo supports versioning for a single product, which covers most cases, but in the case a single Hugo site might need to contain multiple products with different versions each, there is no natively supported way to achieve this.

Context

Using Hugo v0.154.3.

If there is a Hugo site with Product A and Product B, and both have versions (v1.0.0 and v1.1.0 for Product A, and v12.0.0 and v13.0.0 for Product B), we ideally have a file structure like:

/                              # root (landing)
/product-a/1.0.0/              # Product A v1.0.0
/product-a/1.1.0/              # Product A v1.1.0
/product-b/12.0.0/             # Product B v12.0.0
/product-b/13.0.0/             # Product B v13.0.0

But current implementations using roles:

[roles.root]
weight = 1
[roles.product-a]
weight = 2
[roles.product-b]
weight = 3

[versions.root]
weight = 1
[versions."1.0.0"]
weight = 10
[versions."1.1.0"]
weight = 11
[versions."12.0.0"]
weight = 20
[versions."13.0.0"]
weight = 21

would actually give us this:

/                              ✓ valid
/1.0.0/                        ✗ stub (root role with product-a version)
/1.1.0/                        ✗ stub
/12.0.0/                       ✗ stub
/13.0.0/                       ✗ stub
/product-a/1.0.0/              ✓ valid
/product-a/1.1.0/              ✓ valid
/product-a/12.0.0/             ✗ stub (product-a with product-b version)
/product-a/13.0.0/             ✗ stub
/product-b/1.0.0/              ✗ stub (product-b with product-a version)
/product-b/1.1.0/              ✗ stub
/product-b/12.0.0/             ✓ valid
/product-b/13.0.0/             ✓ valid

Result is 13 sitemaps with 8 invalid stub pages (should be 5). Of course we can add some post-build step to process these invalid pages, but I think we should get to the core of the issue instead of applying a fragile and ugly band-aid.

Core Issue

In hugo/hugolib/site.go (lines 396-433) here, Hugo creates a 3D array of sites:

go
sitesVersionsRoles := make([][][]*Site, len(sites))
for i := 0; i < len(sites); i++ {
    sitesVersionsRoles[i] = make([][]*Site, len(versionsSorted))
    for j := range versionsSorted {
        sitesVersionsRoles[i][j] = make([]*Site, len(rolesSorted))
    }
}

This is a full Cartesian product: every language × every version × every role.

Content Routing vs Site Creation

  • Module mounts with sites.matrix control content routing (which content appears in which sites)
  • But Hugo still creates all site combinations regardless of whether content exists
  • Home pages are auto-generated for every site vector (content_map_page_assembler.go:570-604)

Proposed Solution: Sparse Role×Version Matrix

Allow roles to declare which versions are valid:

toml
[roles.product-a]
  weight = 1
  versions = ["1.0.0", "1.1.0"]   # Only these combinations

[roles.product-b]
  weight = 2  
  versions = ["12.0.0", "13.0.0"] # Only these combinations

[roles.root]
  weight = 0
  versions = ["root"]             # Landing page

Hugo would only create sites for declared combinations:

  • root × root → /
  • product-a × 1.0.0 → /product-a/1.0.0/
  • product-a × 1.1.0 → /product-a/1.1.0/
  • product-b × 12.0.0 → /product-b/12.0.0/
  • product-b × 13.0.0 → /product-b/13.0.0/

Using a bit of AI to see where the update can apply, I propose the changes to the following area:

File Change
hugolib/roles/roles.go Add Versions []string to RoleConfig
hugolib/site.go Filter site creation loop
config/allconfig/allconfig.go Update AllSitesMatrix construction
hugolib/sitesmatrix/vectorstores.go Add sparse matrix builder

Behavior

  • Empty versions = all versions (backward compatible)
  • Supports glob patterns: versions = ["1.*", "2.*"]
  • Error if pattern matches zero versions
  • Error if default version invalid for default role