From eceeb19751e78ed76f43a68fb5ce5251837e1049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 20 Feb 2024 17:31:26 +0100 Subject: [PATCH] Fix rebuilding of pages without default content language Fixes #12082 --- hugolib/content_map_page.go | 73 ++++++++++++++++++------------------- hugolib/rebuild_test.go | 37 +++++++++++++++++++ 2 files changed, 73 insertions(+), 37 deletions(-) diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index 9994fb04f..5f0b11210 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -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()) + key := p.Base() + var ids []identity.Identity + // We need only one identity sample per dimensio. + nCount := 0 + cb := func(n contentNodeI) bool { + if n == nil { + return false + } + n.MarkStale() + if nCount > 0 { + return true + } + nCount++ + n.ForEeachIdentity(func(id identity.Identity) bool { + ids = append(ids, id) + return false + }) + + 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 - 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 -} + tree = t.treeResources + nCount = 0 + tree.ForEeachInDimension(key, doctree.DimensionLanguage.Index(), + cb, + ) -func (t *pageTrees) collectAndMarkStaleIdentitiesFor(key string) []identity.Identity { - 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) - return false - }) - if n, ok := tree.GetRaw(key); ok { - n.MarkStale() - } } - - 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 } diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go index cf98f55da..54d6888c0 100644 --- a/hugolib/rebuild_test.go +++ b/hugolib/rebuild_test.go @@ -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|

P1 nn.

") + b.EditFileReplaceAll("content/nn/p1nn/index.md", "P1 nn.", "P1 nn edit.").Build() + b.AssertFileContent("public/nn/p1nn/index.html", "Single: P1 nn|

P1 nn edit.

\n|") + b.AssertFileContent("public/nn/p1nn/index.html", "P1 nn edit.") +} + func TestRebuildVariationsAssetsSassImport(t *testing.T) { if !htesting.IsCI() { t.Skip("skip CI only")