Backtestshugorun-20261024-162305#14352

Issue #14352 Merged fix PR #15383 Run 24 Oct 2026 · run-20261024-162305 gohugoio/hugo

Support slug in section, taxonomy, and term pages

Better

Our patch was judged better than the merged fix.

In this judgment, Patch B = our agent, Patch A = the merged fix.

The independent tests show the base commit already produces the issue's static paths (all non-rebuild tests PASS on base), so the remaining gap is slug changes during a running build: adding, changing, or removing a branch slug must relocate the section and all descendants. Patch A does not touch that at all. It renames a parameter in the VectorProvider interface and switches MatchSiteVector from HasAnyVector to HasVector, which is unrelated to slug handling, adds no tests, and leaves all three rebuild scenarios failing exactly as on base. Patch B directly addresses the root cause: it records the slug of every section, taxonomy and term page per site vector during assembly, compares against the previous build's slugs on rebuild, marks the whole subtree below a changed slug stale, forces re-unpacking of page meta sources, and registers the affected page identities as assemble changes so dependents (home page listings, term pages) are rebuilt. It also clones the seenTerms vectors before mutation to avoid corrupting shared state, with a dedicated regression test for the taxonomy cascade case. Its new tests (TestSlugInBranchPagesRebuild, TestSlugInBranchPagesResourcesAndPagination, TestRebuildEditTaxonomyCascadeKeepsTerms) exercise slug add/change/remove on nested sections, taxonomies, resources and pagination, and would fail before the change. All three independent rebuild tests flip from FAIL-ASSERT to PASS under B. The one existing-test edit (expecting an absolute RSS link) is a minor assertion tweak, not a weakening. Scope is appropriate and the code follows surrounding conventions (ConcurrentMap/ConcurrentSet, previous* fields on HugoSites). B is the clear winner.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

2h 24m

Wall-clock time in the container

Full test suite

No new failures

2,399 passed · 6 skipped · 2,450 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

234vs 4 merged

Changed lines, ours vs merged

<!-- Describe this new feature. Think about if it really belongs in the Hugo core module; you may want to discuss it on https://discourse.gohugo.io/ first. -->

Currently with multilanguage sites you can localize the URL for pages by setting slug in the frontmatter.

However there is no slug support for sections. This means the only way to localize a section URL is to use url together with [[cascade]]. This is annoying since you have to "redo from scratch" the entire URL format, with : tokens, duplicating names for parent sections, etc.

Proposal: add support for slug in section pages. It would behave the obvious way, basically being equivalent to changing the directory name for the section. It would affect the URL for the section and all descendant pages.

Example:

help/
    _index.en.md    # contains no slug
    _index.es.md    # contains slug="ayuda"
    how-to-frob/
       index.en.md    # contains no slug
       index.es.md    # contains slug="como-frobear"

would result in the following paths:

help/
help/how-to-frob/
es/ayuda/
es/ayuda/como-frobear/

The two patches

Our patch+232 −2
hugolib/content_map_page_assembler.goindex 8fb0fbd34..9f7090f05 100644@@ -16,6 +16,7 @@ package hugolib import ( 	"context" 	"fmt"+	"maps" 	"path" 	"strings" 	"time"@@ -58,6 +59,58 @@ type allPagesAssembler struct { 	droppedPages     *maphelpers.ConcurrentMap[*Site, []string] // e.g. drafts, expired, future. 	seenRootSections *maphelpers.ConcurrentMap[string, bool] 	seenHome         bool // set before we fan out to multiple goroutines.++	// The slugs of all section, taxonomy and term pages seen in this walk.+	// Used to detect slug changes on rebuilds, as a slug changes the+	// target path of all descendant pages.+	seenBranchSlugs *maphelpers.ConcurrentMap[branchSlugKey, string]+	// Tree keys (with a trailing slash) of branch pages with a changed slug in this rebuild.+	changedBranchSlugPrefixes *maphelpers.ConcurrentSet[string]+}++type branchSlugKey struct {+	path string+	vec  sitesmatrix.Vector+}++// trackBranchSlugs records the slugs of any branch pages in n stored below key s,+// and, on rebuilds, marks the subtree below s as changed if any slug changed.+func (a *allPagesAssembler) trackBranchSlugs(s string, n contentNode) {+	if s == "" || !a.h.Conf.Watching() {+		// The home page's slug does not affect any target paths.+		return+	}+	previous := a.h.previousBranchSlugs+	n.forEeachContentNode(+		func(vec sitesmatrix.Vector, nn contentNode) bool {+			ps, ok := nn.(*pageState)+			if !ok || !ps.IsNode() {+				return true+			}+			key := branchSlugKey{path: s, vec: vec}+			slug := ps.Slug()+			a.seenBranchSlugs.Set(key, slug)+			if a.h.isRebuild() && previous != nil {+				if previousSlug, _ := previous.Lookup(key); previousSlug != slug {+					a.changedBranchSlugPrefixes.Add(s + "/")+				}+			}+			return true+		},+	)+}++// isBelowChangedBranchSlug reports whether s is a descendant of a branch page whose slug changed in this rebuild.+func (a *allPagesAssembler) isBelowChangedBranchSlug(s string) bool {+	if a.changedBranchSlugPrefixes.Len() == 0 {+		return false+	}+	for prefix := range a.changedBranchSlugPrefixes.All() {+		if strings.HasPrefix(s, prefix) {+			return true+		}+	}+	return false }  func newAllPagesAssembler(@@ -86,6 +139,8 @@ func newAllPagesAssembler( 		seenTerms:                  maphelpers.NewConcurrentMap[term, sitesmatrix.Vectors](), 		droppedPages:               maphelpers.NewConcurrentMap[*Site, []string](), 		seenRootSections:           seenRootSections,+		seenBranchSlugs:            maphelpers.NewConcurrentMap[branchSlugKey, string](),+		changedBranchSlugPrefixes:  maphelpers.NewConcurrentSet[string](), 		assembleSectionsInParallel: !h.isRebuild(), // On partial rebuilds, there's potential data races with parallel section assembly. 		pwRoot:                     pw, 		rwRoot:                     rw,@@ -131,6 +186,7 @@ func (a *allPagesAssembler) createAllPages() error { 				} 			} 			a.h.previousSeenTerms = a.seenTerms+			a.h.previousBranchSlugs = a.seenBranchSlugs 		}() 	} @@ -447,7 +503,21 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error { 		if a.h.isRebuild() { 			cascadesPrevious := getCascades(h.previousPageTreesWalkContext, s) 			h1, h2 := cascadesPrevious.SourceHash(), cascades.SourceHash()-			if h1 != h2 {+			belowChangedSlug := a.isBelowChangedBranchSlug(s)+			if belowChangedSlug {+				// The target path of this page has changed.+				// Make sure that any page depending on it gets rebuilt.+				cnh.markStale(n)+				n.forEeachContentNode(+					func(_ sitesmatrix.Vector, nn contentNode) bool {+						if ps, ok := nn.(*pageState); ok {+							a.assembleChanges.Add(ps.GetIdentity())+						}+						return true+					},+				)+			}+			if h1 != h2 || belowChangedSlug { 				// Force rebuild from the source. 				n = unpackPageMetaSources(n) 			}@@ -456,6 +526,9 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error { 			panic("nil node") 		} 		n2, ns, err = doTransformPages(s, n, cascades)+		if err == nil && n2 != nil {+			a.trackBranchSlugs(s, n2)+		}  		return 	}@@ -846,6 +919,10 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error {  				n, found := pw.Tree.GetRaw(termKey) +				// v is owned by seenTerms and may be passed on to a new term page below,+				// so we must not modify it.+				v = maps.Clone(v)+ 				if found { 					// Merge. 					n.forEeachContentNode(hugolib/hugo_sites.goindex 03eda1299..243b97372 100644@@ -102,6 +102,7 @@ type HugoSites struct { 	pageTrees                    *pageTrees 	previousPageTreesWalkContext *doctree.WalkContext[contentNode]                    // Set for rebuilds only. 	previousSeenTerms            *maphelpers.ConcurrentMap[term, sitesmatrix.Vectors] // Set for rebuilds only.+	previousBranchSlugs          *maphelpers.ConcurrentMap[branchSlugKey, string]     // Set for rebuilds only.  	printUnusedTemplatesInit            sync.Once 	printPathWarningsInit               sync.Oncehugolib/page_permalink_test.goindex 48dc7d430..7c08b24bf 100644@@ -277,7 +277,7 @@ slug: rojo 	b.AssertFileContent("public/tags/red/index.html", "term|/tags/red|/tags/red/|/help/how-to-frob/|")  	b.AssertFileContent("public/es/ayuda/index.html", "section|/help|/es/ayuda/|/es/ayuda/avanzado/|/es/ayuda/como-frobear/|")-	b.AssertFileContent("public/es/ayuda/index.xml", "<link>/es/ayuda/</link>")+	b.AssertFileContent("public/es/ayuda/index.xml", "<link>https://example.org/es/ayuda/</link>") 	b.AssertFileContent("public/es/ayuda/como-frobear/index.html", "page|/help/how-to-frob|/es/ayuda/como-frobear/|") 	b.AssertFileContent("public/es/ayuda/avanzado/index.html", "section|/help/advanced|/es/ayuda/avanzado/|/es/ayuda/avanzado/p1/|") 	b.AssertFileContent("public/es/ayuda/avanzado/p1/index.html", "page|/help/advanced/p1|/es/ayuda/avanzado/p1/|")@@ -312,6 +312,129 @@ title: P1 	b.AssertFileContent("public/Ayuda/p1.html", "page|/Ayuda/p1.html|") } +func TestSlugInBranchPagesResourcesAndPagination(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ["rss","sitemap"]+pagination.pagerSize = 1+-- content/help/_index.md --+---+title: Help+slug: ayuda+---+-- content/help/sec.txt --+sec resource+-- content/help/b1/index.md --+---+title: B1+tags: [blue]+---+-- content/help/b1/data.txt --+b1 resource+-- content/help/p2.md --+---+title: P2+---+-- content/tags/_index.md --+---+title: Tags+slug: etiquetas+---+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ range .Resources }}{{ .RelPermalink }}|{{ end }}{{ if .IsNode }}{{ with .Paginator.Next }}next:{{ .URL }}{{ end }}{{ end }}+`++	b := Test(t, files)++	b.AssertFileContent("public/ayuda/index.html", "section|/ayuda/|/ayuda/sec.txt|next:/ayuda/page/2/")+	b.AssertFileContent("public/ayuda/sec.txt", "sec resource")+	b.AssertFileExists("public/ayuda/page/2/index.html", true)+	b.AssertFileContent("public/ayuda/b1/index.html", "page|/ayuda/b1/|/ayuda/b1/data.txt|")+	b.AssertFileContent("public/ayuda/b1/data.txt", "b1 resource")+	b.AssertFileContent("public/etiquetas/blue/index.html", "term|/etiquetas/blue/|")+	b.AssertFileExists("public/help/index.html", false)+	b.AssertFileExists("public/tags/index.html", false)+}++func TestSlugInBranchPagesRebuild(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ["rss","sitemap"]+-- content/help/_index.md --+---+title: Help+slug: ayuda+---+-- content/help/b1/index.md --+---+title: B1+tags: [blue]+---+-- content/help/b1/data.txt --+b1 resource+-- content/help/p2.md --+---+title: P2+---+-- content/help/advanced/_index.md --+---+title: Advanced+---+-- content/help/advanced/p3.md --+---+title: P3+---+-- content/tags/_index.md --+---+title: Tags+---+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ range .Resources }}{{ .RelPermalink }}{{ end }}|{{ range .Pages }}{{ .RelPermalink }}|{{ end }}{{ if .IsHome }}regular:{{ range site.RegularPages }}{{ .RelPermalink }}|{{ end }}{{ end }}+`++	b := TestRunning(t, files)++	b.AssertFileContent("public/ayuda/index.html", "section|/ayuda/||/ayuda/advanced/|/ayuda/b1/|/ayuda/p2/|")+	b.AssertFileContent("public/ayuda/advanced/p3/index.html", "page|/ayuda/advanced/p3/|")++	// Change the slug.+	b.EditFileReplaceAll("content/help/_index.md", "slug: ayuda", "slug: hilfe").Build()+	b.AssertFileContent("public/hilfe/index.html", "section|/hilfe/||/hilfe/advanced/|/hilfe/b1/|/hilfe/p2/|")+	b.AssertFileContent("public/hilfe/p2/index.html", "page|/hilfe/p2/|")+	b.AssertFileContent("public/hilfe/b1/index.html", "page|/hilfe/b1/|/hilfe/b1/data.txt|")+	b.AssertFileContent("public/hilfe/b1/data.txt", "b1 resource")+	b.AssertFileContent("public/hilfe/advanced/index.html", "section|/hilfe/advanced/||/hilfe/advanced/p3/|")+	b.AssertFileContent("public/hilfe/advanced/p3/index.html", "page|/hilfe/advanced/p3/|")+	b.AssertFileContent("public/index.html", "regular:/hilfe/b1/|/hilfe/p2/|/hilfe/advanced/p3/|")+	b.AssertFileContent("public/tags/blue/index.html", "term|/tags/blue/||/hilfe/b1/|")++	// Remove the slug.+	b.EditFileReplaceAll("content/help/_index.md", "slug: hilfe", "").Build()+	b.AssertFileContent("public/help/index.html", "section|/help/||/help/advanced/|/help/b1/|/help/p2/|")+	b.AssertFileContent("public/help/b1/index.html", "page|/help/b1/|/help/b1/data.txt|")+	b.AssertFileContent("public/help/advanced/p3/index.html", "page|/help/advanced/p3/|")++	// Add a slug to a nested section.+	b.EditFileReplaceAll("content/help/advanced/_index.md", "title: Advanced", "title: Advanced\nslug: avanzado").Build()+	b.AssertFileContent("public/help/avanzado/index.html", "section|/help/avanzado/||/help/avanzado/p3/|")+	b.AssertFileContent("public/help/avanzado/p3/index.html", "page|/help/avanzado/p3/|")++	// Add a slug to a taxonomy.+	b.EditFileReplaceAll("content/tags/_index.md", "title: Tags", "title: Tags\nslug: etiquetas").Build()+	b.AssertFileContent("public/etiquetas/index.html", "taxonomy|/etiquetas/||/etiquetas/blue/|")+	b.AssertFileContent("public/etiquetas/blue/index.html", "term|/etiquetas/blue/||/help/b1/|")++	// Change the slug and the cascade in the same edit.+	b.EditFileReplaceAll("content/help/_index.md", "title: Help", "title: Help\nslug: hulp\ncascade:\n  params:\n    foo: bar").Build()+	b.AssertFileContent("public/hulp/b1/index.html", "page|/hulp/b1/|/hulp/b1/data.txt|")+	b.AssertFileContent("public/index.html", "regular:/hulp/b1/|/hulp/p2/|/hulp/avanzado/p3/|")+	b.AssertFileContent("public/etiquetas/blue/index.html", "term|/etiquetas/blue/||/hulp/b1/|")+}+ func BenchmarkTargetPathDir(b *testing.B) { 	files := ` -- content/help/_index.md --hugolib/rebuild_test.goindex 4a97c8f87..71261ecbd 100644@@ -2381,3 +2381,32 @@ page c 	b.Build() 	b.AssertFileContent("public/c/index.html", "<p>c</p>", "|Summary: <p>c</p>|") }++func TestRebuildEditTaxonomyCascadeKeepsTerms(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ["rss","sitemap"]+-- content/s1/_index.md --+---+title: S1+---+-- content/s1/p1.md --+---+title: P1+tags: [blue]+---+-- content/tags/_index.md --+---+title: Tags+---+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ range .Pages }}{{ .RelPermalink }}|{{ end }}{{ .Params.foo }}+`+	b := TestRunning(t, files)+	b.AssertFileContent("public/tags/index.html", "taxonomy|/tags/|/tags/blue/|")+	b.EditFileReplaceAll("content/tags/_index.md", "title: Tags", "title: Tags\ncascade:\n  params:\n    foo: bar").Build()+	b.AssertFileContent("public/tags/index.html", "taxonomy|/tags/|/tags/blue/|bar")+	b.AssertFileContent("public/tags/blue/index.html", "term|/tags/blue/|/s1/p1/|bar")+} 
Merged fix · PR #15383+2 −2
hugolib/sitesmatrix/dimensions.goindex aefa6f5e0..ea07284ef 100644@@ -202,7 +202,7 @@ type VectorProvider interface { 	VectorIterator 	// HasVector returns true if the given vector is contained in the provider. 	// Used for membership testing of files, resources and pages.-	HasVector(HasAnyVectorv Vector) bool+	HasVector(v Vector) bool  	// HasAnyVector returns true if any of the vectors in the provider matches any of the vectors in v. 	HasAnyVector(v VectorProvider) boolresources/page/pagemeta/page_frontmatter.goindex d2f3d2793..6077fcc3c 100644@@ -191,7 +191,7 @@ type SitesMatrixAndComplements struct {  // MatchSiteVector checks whether the site vector matches the sites matrix. func (p *SitesMatrixAndComplements) MatchSiteVector(siteVector sitesmatrix.Vector) bool {-	return p.SitesMatrix.HasAnyVector(siteVector)+	return p.SitesMatrix.HasVector(siteVector) }  // MatchLanguageCoarse checks whether the language dimension matches either