Backtestshugorun-20261007-020926#14352

Issue #14352 Merged fix PR #15383 Run 7 Oct 2026 · run-20261007-020926 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.

Patch A does not address slug support for section, taxonomy, or term pages. It renames an interface parameter, fixing the typo `HasAnyVectorv`, and switches `MatchSiteVector` from `HasAnyVector` to `HasVector`. Neither change touches URL or slug computation, and A adds no tests. Patch B works on the slug feature directly. It records the slugs of ancestor branch nodes in the walk context and compares them between the previous and current build. When an ancestor slug changes, it rebuilds descendants from source and marks their identities as changed, so target paths of all descendant pages update. This is exactly the issue's requirement that a section slug affect the section and all descendants, and it covers the server/rebuild case. B also clones the term `sitesMatrixBase` map so a later merge cannot mutate it, which keeps rebuild-from-source correct for terms. B adds a thorough rebuild test covering changing, removing and adding nested section slugs and changing a taxonomy slug, plus a taxonomy cascade rebuild test. It changes one existing assertion to expect an absolute RSS link; this is a minor, unexplained change but plausible. B is the only patch that meaningfully addresses the issue, with substantive tests.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

55m 59s

Wall-clock time in the container

Full test suite

No new failures

3,807 passed · 101 skipped · 3,910 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

181vs 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+178 −3
hugolib/content_map_page_assembler.goindex 8fb0fbd34..529f1b12b 100644@@ -16,7 +16,9 @@ package hugolib import ( 	"context" 	"fmt"+	"maps" 	"path"+	"sort" 	"strings" 	"time" @@ -28,6 +30,7 @@ import ( 	"github.com/gohugoio/hugo/hugofs/files" 	"github.com/gohugoio/hugo/hugolib/doctree" 	"github.com/gohugoio/hugo/hugolib/sitesmatrix"+	"github.com/gohugoio/hugo/identity" 	"github.com/gohugoio/hugo/media" 	"github.com/gohugoio/hugo/output" 	"github.com/gohugoio/hugo/resources"@@ -38,6 +41,10 @@ import ( 	"golang.org/x/sync/errgroup" ) +// slugsWalkContextKeyPrefix is the key prefix used to store branch slugs in+// the walk context data, kept separate from the cascade keys (which start with "/").+const slugsWalkContextKeyPrefix = "__slugs"+ // Handles the flow of creating all the pages and resources for all sites. // This includes applying any cascade configuration passed down the tree. type allPagesAssembler struct {@@ -223,6 +230,19 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error { 		return cascades 	} +	// getAncestorSlugs returns the slugs set in the branch nodes above s+	// (not including s itself), as a string suitable for change detection.+	getAncestorSlugs := func(wctx *doctree.WalkContext[contentNode], s string) string {+		if s == "" {+			return ""+		}+		_, data := wctx.Data().LongestPrefix(slugsWalkContextKeyPrefix + s)+		if v, ok := data.(string); ok {+			return v+		}+		return ""+	}+ 	doTransformPages := func(s string, n contentNode, cascades *page.PageMatcherParamsConfigs) (n2 contentNode, ns doctree.NodeTransformState, err error) { 		defer func() { 			cascadesLen := cascades.Len()@@ -245,6 +265,25 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error { 				// New cascade values added, pass them downwards. 				rw.WalkContext.Data().Insert(paths.AddTrailingSlash(s), cascades) 			}++			if n2 != nil && s != "" && cnh.isBranchNode(n2) {+				// Slugs in branch nodes affect the target path of all descendants,+				// pass them downwards so we can detect changes on rebuilds.+				var slugs []string+				n2.forEeachContentNode(+					func(vec sitesmatrix.Vector, nn contentNode) bool {+						if ps, ok := nn.(*pageState); ok && ps.Slug() != "" {+							slugs = append(slugs, fmt.Sprintf("%v:%s", vec, ps.Slug()))+						}+						return true+					},+				)+				if len(slugs) > 0 {+					sort.Strings(slugs)+					v := getAncestorSlugs(rw.WalkContext, s) + s + "=" + strings.Join(slugs, ",") + "|"+					rw.WalkContext.Data().Insert(slugsWalkContextKeyPrefix+paths.AddTrailingSlash(s), v)+				}+			} 		}()  		var handlePageMetaSource func(v contentNode, n contentNodesMap, replaceVector bool) (n2 contentNode, err error)@@ -450,6 +489,15 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error { 			if h1 != h2 { 				// Force rebuild from the source. 				n = unpackPageMetaSources(n)+			} else if getAncestorSlugs(h.previousPageTreesWalkContext, s) != getAncestorSlugs(rw.WalkContext, s) {+				// A slug in one of the sections above has changed,+				// force rebuild from the source to get the new target paths,+				// and make sure that pages linking to the old ones gets re-rendered.+				cnh.toForEachIdentityProvider(n).ForEeachIdentity(func(id identity.Identity) bool {+					a.assembleChanges.Add(id)+					return false+				})+				n = unpackPageMetaSources(n) 			} 		} 		if n == nil {@@ -858,8 +906,11 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error {  				if len(v) > 0 { 					p := &pageMetaSource{-						pathInfo:        pi,-						sitesMatrixBase: v,+						pathInfo: pi,+						// Clone the vectors, v may be modified when merging with+						// existing term nodes later on (see above), and the sites+						// matrix is needed when this page is rebuilt from source.+						sitesMatrixBase: maps.Clone(v), 						pageConfigSource: &pagemeta.PageConfigEarly{ 							Kind: kinds.KindTerm, 						},hugolib/page_permalink_test.goindex 48dc7d430..992cdae53 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,95 @@ title: P1 	b.AssertFileContent("public/Ayuda/p1.html", "page|/Ayuda/p1.html|") } +func TestSlugInBranchPagesRebuild(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ["rss", "sitemap"]+defaultContentLanguage = "en"+[languages.en]+weight = 1+[languages.es]+weight = 2+[taxonomies]+tag = "tags"+-- content/help/_index.en.md --+---+title: Help+---+-- content/help/_index.es.md --+---+title: Ayuda+slug: ayuda+---+-- content/help/p1.es.md --+---+title: P1+---+-- content/help/sub/_index.es.md --+---+title: Sub+---+-- content/help/sub/p2.es.md --+---+title: P2+tags: [red]+---+-- content/help/sub/deeper/_index.es.md --+---+title: Deeper+slug: mas+---+-- content/help/sub/deeper/p3.es.md --+---+title: P3+---+-- content/tags/_index.es.md --+---+title: Etiquetas+slug: etiquetas+---+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ range .Pages }}{{ .RelPermalink }}|{{ end }}+`++	b := TestRunning(t, files)++	b.AssertFileContent("public/es/ayuda/sub/mas/index.html", "section|/es/ayuda/sub/mas/|/es/ayuda/sub/mas/p3/|")+	b.AssertFileContent("public/es/etiquetas/red/index.html", "term|/es/etiquetas/red/|/es/ayuda/sub/p2/|")++	// Change the slug of the top level section.+	b.EditFileReplaceAll("content/help/_index.es.md", "slug: ayuda", "slug: soporte").Build()++	b.AssertFileContent("public/es/soporte/index.html", "section|/es/soporte/|/es/soporte/p1/|/es/soporte/sub/|")+	b.AssertFileContent("public/es/soporte/p1/index.html", "page|/es/soporte/p1/|")+	b.AssertFileContent("public/es/soporte/sub/index.html", "section|/es/soporte/sub/|/es/soporte/sub/mas/|/es/soporte/sub/p2/|")+	b.AssertFileContent("public/es/soporte/sub/p2/index.html", "page|/es/soporte/sub/p2/|")+	b.AssertFileContent("public/es/soporte/sub/mas/index.html", "section|/es/soporte/sub/mas/|/es/soporte/sub/mas/p3/|")+	b.AssertFileContent("public/es/soporte/sub/mas/p3/index.html", "page|/es/soporte/sub/mas/p3/|")+	b.AssertFileContent("public/es/etiquetas/red/index.html", "term|/es/etiquetas/red/|/es/soporte/sub/p2/|")+	b.AssertFileContent("public/help/index.html", "section|/help/|")++	// Remove the slug of the top level section.+	b.EditFileReplaceAll("content/help/_index.es.md", "slug: soporte", "").Build()++	b.AssertFileContent("public/es/help/sub/index.html", "section|/es/help/sub/|/es/help/sub/mas/|/es/help/sub/p2/|")+	b.AssertFileContent("public/es/help/sub/mas/p3/index.html", "page|/es/help/sub/mas/p3/|")++	// Add a slug to a nested section.+	b.EditFileReplaceAll("content/help/sub/_index.es.md", "title: Sub", "title: Sub\nslug: bajo").Build()++	b.AssertFileContent("public/es/help/bajo/index.html", "section|/es/help/bajo/|/es/help/bajo/mas/|/es/help/bajo/p2/|")+	b.AssertFileContent("public/es/help/bajo/mas/p3/index.html", "page|/es/help/bajo/mas/p3/|")++	// Change the slug of the taxonomy.+	b.EditFileReplaceAll("content/tags/_index.es.md", "slug: etiquetas", "slug: marcas").Build()++	b.AssertFileContent("public/es/marcas/index.html", "taxonomy|/es/marcas/|/es/marcas/red/|")+	b.AssertFileContent("public/es/marcas/red/index.html", "term|/es/marcas/red/|/es/help/bajo/p2/|")+}+ func BenchmarkTargetPathDir(b *testing.B) { 	files := ` -- content/help/_index.md --hugolib/rebuild_test.goindex 4a97c8f87..6ad77fb13 100644@@ -877,6 +877,41 @@ func TestRebuildEditHomeCascadeRemoveParam(t *testing.T) { 	b.AssertFileContent("public/mysection/p1/index.html", "all. P1|Param: |") } +func TestRebuildEditTaxonomyCascadeKeepsTerms(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+disableKinds = ["rss", "sitemap"]+[taxonomies]+tag = "tags"+-- content/tags/_index.md --+---+title: Tags+cascade:+  params:+    color: blue+---+-- content/mysection/_index.md --+---+title: My Section+---+-- content/mysection/p1.md --+---+title: P1+tags: [red]+---+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ .Params.color }}|{{ range .Pages }}{{ .RelPermalink }}:{{ .Params.color }}|{{ end }}+`++	b := TestRunning(t, files)+	b.AssertFileContent("public/tags/index.html", "taxonomy|/tags/|blue|/tags/red/:blue|")+	b.EditFileReplaceAll("content/tags/_index.md", "color: blue", "color: green").Build()+	b.AssertFileContent("public/tags/index.html", "taxonomy|/tags/|green|/tags/red/:green|")+	b.AssertFileContent("public/tags/red/index.html", "term|/tags/red/|green|/mysection/p1/:|")+}+ func TestRebuildEditHomeCascadeEditDate(t *testing.T) { 	t.Parallel() 	b := TestRunning(t, rebuildBasicFiles) 
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