Backtestshugorun-20261013-011256#14352

Issue #14352 Merged fix PR #15383 Run 13 Oct 2026 · run-20261013-011256 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 the issue at all. It renames an interface parameter and swaps HasAnyVector for HasVector in MatchSiteVector. That is unrelated churn, and possibly a semantic change, with no connection to slug support for sections, taxonomies or terms. It adds no tests.

Patch B targets the slug feature directly. The repository apparently already has base slug support, since the existing test in page_permalink_test.go expects /es/ayuda/ paths. Patch B fixes what is still missing for live rebuilds. It tracks a per-branch slug signature tree, compares that tree against the previous build, and forces affected descendants to be rebuilt from source and their identities marked changed. It also fixes two latent bugs that the rebuild path exposes: contentNodesMap unpacking of page meta sources, and aliasing of the term sitesMatrixBase map (fixed with maps.Clone).

Patch B adds several meaningful rebuild tests covering:
- section slug edits that propagate to descendants, resources and terms
- taxonomy slug edits
- cascade terms without a content file
- a slug edit combined with adding a new language
- a slug edit combined with a cascade edit

It also adjusts one existing assertion to the absolute RSS link. That adjustment is slightly suspicious, but it is plausible for an index.xml <link> to carry the baseURL.

Patch B is clearly the better fix.

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

1h 59m

Wall-clock time in the container

Full test suite

No new failures

2,287 passed · 95 skipped · 2,389 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

328vs 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+319 −9
hugolib/content_map_page_assembler.goindex 8fb0fbd34..82e807848 100644@@ -16,7 +16,9 @@ package hugolib import ( 	"context" 	"fmt"+	"maps" 	"path"+	"sort" 	"strings" 	"time" @@ -58,6 +60,11 @@ 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.++	// Maps branch keys (with a trailing slash) to a signature of the slugs+	// set in that branch and its ancestors. The target paths of all+	// descendants depend on these slugs.+	branchSlugs *doctree.SimpleThreadSafeTree[string] }  func newAllPagesAssembler(@@ -86,6 +93,7 @@ func newAllPagesAssembler( 		seenTerms:                  maphelpers.NewConcurrentMap[term, sitesmatrix.Vectors](), 		droppedPages:               maphelpers.NewConcurrentMap[*Site, []string](), 		seenRootSections:           seenRootSections,+		branchSlugs:                doctree.NewSimpleThreadSafeTree[string](), 		assembleSectionsInParallel: !h.isRebuild(), // On partial rebuilds, there's potential data races with parallel section assembly. 		pwRoot:                     pw, 		rwRoot:                     rw,@@ -143,6 +151,18 @@ func (a *allPagesAssembler) createAllPages() error { 	return nil } +// ancestorSlugsChanged reports whether any slug set in the branch pages above+// s has changed since the previous build.+// The target paths of the pages below a branch page depend on these slugs.+func (a *allPagesAssembler) ancestorSlugsChanged(s string) bool {+	if s == "" || a.h.previousBranchSlugs == nil {+		return false+	}+	_, sigPrevious := a.h.previousBranchSlugs.LongestPrefix(s)+	_, sig := a.branchSlugs.LongestPrefix(s)+	return sigPrevious != sig+}+ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error { 	var ( 		sites     = a.h.sitesVersionsRolesMap@@ -245,6 +265,27 @@ 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 != "" {+				// Slugs set in section, taxonomy and term pages are applied+				// to the target paths of all descendants, pass them downwards.+				var slugs []string+				n2.forEeachContentNode(+					func(vec sitesmatrix.Vector, nn contentNode) bool {+						if p, ok := nn.(*pageState); ok && p.IsBranch() {+							if slug := p.m.Slug(); slug != "" {+								slugs = append(slugs, fmt.Sprintf("%v=%s", vec, slug))+							}+						}+						return true+					},+				)+				if len(slugs) > 0 {+					sort.Strings(slugs)+					_, parentSig := a.branchSlugs.LongestPrefix(s)+					a.branchSlugs.Insert(paths.AddTrailingSlash(s), parentSig+"|"+s+":"+strings.Join(slugs, ","))+				}+			} 		}()  		var handlePageMetaSource func(v contentNode, n contentNodesMap, replaceVector bool) (n2 contentNode, err error)@@ -426,12 +467,18 @@ func (a *allPagesAssembler) doCreatePages(prefix string, depth int) error { 				seen := map[*pageMetaSource]struct{}{} 				for _, v := range nn { 					vv := unpackPageMetaSources(v)-					pms := vv.(*pageMetaSource)-					if _, found := seen[pms]; !found {-						if !yield(pms) {-							return+					if vv == nil {+						continue+					}+					// v may be a contentNodesMap, which unpacks to a sequence.+					for vvv := range cnh.contentNodeToSeq(vv) {+						pms := vvv.(*pageMetaSource)+						if _, found := seen[pms]; !found {+							if !yield(pms) {+								return+							}+							seen[pms] = struct{}{} 						}-						seen[pms] = struct{}{} 					} 				} 			}@@ -447,7 +494,13 @@ 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 {+			slugsChanged := a.ancestorSlugsChanged(s)+			if slugsChanged {+				// The target paths have changed, make sure that any page+				// linking to this page gets re-rendered.+				a.assembleChanges.Add(cnh.GetIdentity(n))+			}+			if h1 != h2 || slugsChanged { 				// Force rebuild from the source. 				n = unpackPageMetaSources(n) 			}@@ -858,8 +911,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 in the merge above+						// when this hook runs again, and this page may be+						// re-created from this source on rebuilds.+						sitesMatrixBase: maps.Clone(v), 						pageConfigSource: &pagemeta.PageConfigEarly{ 							Kind: kinds.KindTerm, 						},hugolib/hugo_sites.goindex 03eda1299..b856f4b6d 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          *doctree.SimpleThreadSafeTree[string]                // Set for rebuilds only.  	printUnusedTemplatesInit            sync.Once 	printPathWarningsInit               sync.Oncehugolib/hugo_sites_build.goindex 0feaada59..3d9e9a128 100644@@ -339,6 +339,8 @@ func (h *HugoSites) assemble(ctx context.Context, l logg.LevelLogger, bcfg *Buil 		defer func() { 			// Store previous walk context to detect cascade changes on next rebuild. 			h.previousPageTreesWalkContext = apa.rwRoot.WalkContext+			// Store the branch slugs to detect slug changes on next rebuild.+			h.previousBranchSlugs = apa.branchSlugs 		}() 	} hugolib/page_permalink_test.goindex 48dc7d430..b83bc5964 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/|")hugolib/rebuild_test.goindex 4a97c8f87..6209f3f00 100644@@ -2381,3 +2381,254 @@ page c 	b.Build() 	b.AssertFileContent("public/c/index.html", "<p>c</p>", "|Summary: <p>c</p>|") }++// See issue 14352.+func TestRebuildEditSectionSlug(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+[taxonomies]+tag = "tags"+-- content/help/_index.md --+---+title: Help+slug: ayuda+---+-- content/help/p1.md --+---+title: P1+---+-- content/help/sub/_index.md --+---+title: Sub+---+-- content/help/sub/p2/index.md --+---+title: P2+tags: [red]+---+-- content/help/sub/p2/data.txt --+data+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ range .Pages }}{{ .RelPermalink }}|{{ end }}{{ range .Resources }}R:{{ .RelPermalink }}|{{ end }}+`+	b := TestRunning(t, files)++	b.AssertFileContent("public/ayuda/index.html", "section|/ayuda/|/ayuda/p1/|/ayuda/sub/|")+	b.AssertFileContent("public/ayuda/sub/p2/index.html", "page|/ayuda/sub/p2/|R:/ayuda/sub/p2/data.txt|")++	b.EditFileReplaceAll("content/help/_index.md", "slug: ayuda", "slug: aide").Build()++	b.AssertFileContent("public/aide/index.html", "section|/aide/|/aide/p1/|/aide/sub/|")+	b.AssertFileContent("public/aide/p1/index.html", "page|/aide/p1/|")+	b.AssertFileContent("public/aide/sub/index.html", "section|/aide/sub/|/aide/sub/p2/|")+	b.AssertFileContent("public/aide/sub/p2/index.html", "page|/aide/sub/p2/|R:/aide/sub/p2/data.txt|")+	b.AssertFileExists("public/aide/sub/p2/data.txt", true)+	b.AssertFileContent("public/tags/red/index.html", "term|/tags/red/|/aide/sub/p2/|")++	b.EditFileReplaceAll("content/help/_index.md", "slug: aide", "").Build()++	b.AssertFileContent("public/help/index.html", "section|/help/|/help/p1/|/help/sub/|")+	b.AssertFileContent("public/help/sub/index.html", "section|/help/sub/|/help/sub/p2/|")+	b.AssertFileContent("public/help/sub/p2/index.html", "page|/help/sub/p2/|R:/help/sub/p2/data.txt|")+	b.AssertFileContent("public/tags/red/index.html", "term|/tags/red/|/help/sub/p2/|")+}++// See issue 14352.+func TestRebuildEditTaxonomySlug(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+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/sub/_index.es.md --+---+title: Sub+---+-- content/help/sub/p1/index.es.md --+---+title: P1+tags: [red]+---+-- 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/etiquetas/index.html", "taxonomy|/es/etiquetas/|/es/etiquetas/red/|")+	b.AssertFileContent("public/es/etiquetas/red/index.html", "term|/es/etiquetas/red/|/es/ayuda/sub/p1/|")++	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/ayuda/sub/p1/|")+	b.AssertFileContent("public/es/ayuda/sub/p1/index.html", "page|/es/ayuda/sub/p1/|")+}++// Terms without content files must survive being re-created from source on rebuilds.+func TestRebuildEditTaxonomyCascadeTermWithoutContentFile(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+[taxonomies]+tag = "tags"+-- content/s1/_index.md --+---+title: S1+---+-- content/s1/p1.md --+---+title: P1+tags: [red]+---+-- content/tags/_index.md --+---+title: Tags+cascade:+  params:+    foo: bar+---+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ .Params.foo }}|{{ range .Pages }}{{ .RelPermalink }}|{{ end }}+`+	b := TestRunning(t, files)++	b.AssertFileContent("public/tags/red/index.html", "term|/tags/red/|bar|/s1/p1/|")++	b.EditFileReplaceAll("content/tags/_index.md", "foo: bar", "foo: baz").Build()++	b.AssertFileContent("public/tags/index.html", "taxonomy|/tags/|baz|/tags/red/|")+	b.AssertFileContent("public/tags/red/index.html", "term|/tags/red/|baz|/s1/p1/|")+}++// Terms existing in multiple languages must be re-created from source when a+// new language is added in the same rebuild as an ancestor slug change.+func TestRebuildEditTaxonomySlugAndAddTermLanguage(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+defaultContentLanguage = "en"+[languages.en]+weight = 1+[languages.es]+weight = 2+[languages.fr]+weight = 3+[taxonomies]+tag = "tags"+-- content/p1.en.md --+---+title: P1+tags: [red]+---+-- content/p1.es.md --+---+title: P1+tags: [red]+---+-- content/p1.fr.md --+---+title: P1+---+-- content/tags/_index.en.md --+---+title: Tags+slug: t-en+---+-- content/tags/_index.es.md --+---+title: Etiquetas+slug: t-es+---+-- content/tags/_index.fr.md --+---+title: Etiquettes+slug: t-fr+---+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ range .Pages }}{{ .RelPermalink }}|{{ end }}+`+	b := TestRunning(t, files)++	b.AssertFileContent("public/t-en/red/index.html", "term|/t-en/red/|/p1/|")+	b.AssertFileContent("public/es/t-es/red/index.html", "term|/es/t-es/red/|/es/p1/|")++	b.EditFileReplaceAll("content/tags/_index.en.md", "slug: t-en", "slug: x-en")+	b.EditFileReplaceAll("content/tags/_index.es.md", "slug: t-es", "slug: x-es")+	b.EditFileReplaceAll("content/tags/_index.fr.md", "slug: t-fr", "slug: x-fr")+	b.EditFileReplaceAll("content/p1.fr.md", "title: P1", "title: P1\ntags: [red]").Build()++	b.AssertFileContent("public/x-en/red/index.html", "term|/x-en/red/|/p1/|")+	b.AssertFileContent("public/es/x-es/red/index.html", "term|/es/x-es/red/|/es/p1/|")+	b.AssertFileContent("public/fr/x-fr/red/index.html", "term|/fr/x-fr/red/|/fr/p1/|")+}++// Pages linking to a descendant must be re-rendered when a section's slug and+// cascade are changed in the same edit.+func TestRebuildEditSectionSlugAndCascade(t *testing.T) {+	t.Parallel()++	files := `+-- hugo.toml --+baseURL = "https://example.com"+disableLiveReload = true+disableKinds = ["taxonomy", "term"]+-- content/help/_index.md --+---+title: Help+slug: ayuda+cascade:+  params:+    foo: bar+---+-- content/help/p1.md --+---+title: P1+---+-- content/other/_index.md --+---+title: Other+---+-- layouts/all.html --+{{ .Kind }}|{{ .RelPermalink }}|{{ .Params.foo }}|{{ with site.GetPage "/help/p1" }}Link:{{ .RelPermalink }}{{ end }}|+`+	b := TestRunning(t, files)++	b.AssertFileContent("public/other/index.html", "section|/other/||Link:/ayuda/p1/|")++	b.EditFileReplaceAll("content/help/_index.md", "slug: ayuda", "slug: aide").EditFileReplaceAll("content/help/_index.md", "foo: bar", "foo: baz").Build()++	b.AssertFileContent("public/aide/p1/index.html", "page|/aide/p1/|baz|")+	b.AssertFileContent("public/other/index.html", "section|/other/||Link:/aide/p1/|")+} 
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