]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix rebuilding of pages without default content language
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 20 Feb 2024 16:31:26 +0000 (17:31 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 20 Feb 2024 17:42:14 +0000 (18:42 +0100)
Fixes #12082

hugolib/content_map_page.go
hugolib/rebuild_test.go

index 9994fb04f4ef6b5c9890ef5de85cfd85d42e6146..5f0b11210ca818f043f32b7bc0b73132a142ba90 100644 (file)
@@ -130,49 +130,48 @@ type pageTrees struct {
 // so we mark all entries as stale (which will trigger cache invalidation), then
 // return the first.
 func (t *pageTrees) collectAndMarkStaleIdentities(p *paths.Path) []identity.Identity {
-       ids := t.collectAndMarkStaleIdentitiesFor(p.Base())
-
-       if p.Component() == files.ComponentFolderContent {
-               // It may also be a bundled content resource.
-               key := p.ForBundleType(paths.PathTypeContentResource).Base()
-               tree := t.treeResources
-               if n := tree.Get(key); n != nil {
-                       n.ForEeachIdentity(func(id identity.Identity) bool {
-                               ids = append(ids, id)
-                               return false
-                       })
-                       if n, ok := tree.GetRaw(key); ok {
-                               n.MarkStale()
-                       }
-               }
-       }
-       return ids
-}
-
-func (t *pageTrees) collectAndMarkStaleIdentitiesFor(key string) []identity.Identity {
+       key := p.Base()
        var ids []identity.Identity
-       tree := t.treePages
-       if n := tree.Get(key); n != nil {
-               n.ForEeachIdentity(func(id identity.Identity) bool {
-                       ids = append(ids, id)
+       // We need only one identity sample per dimensio.
+       nCount := 0
+       cb := func(n contentNodeI) bool {
+               if n == nil {
                        return false
-               })
-               if n, ok := tree.GetRaw(key); ok {
-                       n.MarkStale()
                }
-       }
-
-       tree = t.treeResources
-       if n := tree.Get(key); n != nil {
+               n.MarkStale()
+               if nCount > 0 {
+                       return true
+               }
+               nCount++
                n.ForEeachIdentity(func(id identity.Identity) bool {
                        ids = append(ids, id)
                        return false
                })
-               if n, ok := tree.GetRaw(key); ok {
-                       n.MarkStale()
-               }
+
+               return false
        }
+       tree := t.treePages
+       nCount = 0
+       tree.ForEeachInDimension(key, doctree.DimensionLanguage.Index(),
+               cb,
+       )
 
+       tree = t.treeResources
+       nCount = 0
+       tree.ForEeachInDimension(key, doctree.DimensionLanguage.Index(),
+               cb,
+       )
+
+       if p.Component() == files.ComponentFolderContent {
+               // It may also be a bundled content resource.
+               key := p.ForBundleType(paths.PathTypeContentResource).Base()
+               tree = t.treeResources
+               nCount = 0
+               tree.ForEeachInDimension(key, doctree.DimensionLanguage.Index(),
+                       cb,
+               )
+
+       }
        return ids
 }
 
index cf98f55da71b08d284272ba970c8ef33f18bb9e1..54d6888c09305f40ca0c63d5badc3df2124f81f1 100644 (file)
@@ -1268,6 +1268,43 @@ Single: {{ .Title }}|{{ .Content }}|Bundled File: {{ with .Resources.GetMatch "f
        b.AssertFileContent("public/nn/p1/index.html", "B nn edit.")
 }
 
+func TestRebuildEditContentNonDefaultLanguageDifferentBundles(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableLiveReload = true
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = true
+[languages]
+[languages.en]
+weight = 1
+contentDir = "content/en"
+[languages.nn]
+weight = 2
+contentDir = "content/nn"
+-- content/en/p1en/index.md --
+---
+title: "P1 en"
+---
+-- content/nn/p1nn/index.md --
+---
+title: "P1 nn"
+---
+P1 nn.
+-- layouts/_default/single.html --
+Single: {{ .Title }}|{{ .Content }}|
+`
+
+       b := TestRunning(t, files)
+
+       b.AssertFileContent("public/nn/p1nn/index.html", "Single: P1 nn|<p>P1 nn.</p>")
+       b.EditFileReplaceAll("content/nn/p1nn/index.md", "P1 nn.", "P1 nn edit.").Build()
+       b.AssertFileContent("public/nn/p1nn/index.html", "Single: P1 nn|<p>P1 nn edit.</p>\n|")
+       b.AssertFileContent("public/nn/p1nn/index.html", "P1 nn edit.")
+}
+
 func TestRebuildVariationsAssetsSassImport(t *testing.T) {
        if !htesting.IsCI() {
                t.Skip("skip CI only")