]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix sample logic when adding content files in server
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 18 Feb 2024 10:33:09 +0000 (11:33 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 18 Feb 2024 11:24:27 +0000 (12:24 +0100)
The partial rebuilds works by calaulating a baseline from a change set.

For new content, this doesn't work, so to avoid rebuilding everything, we first
try to collect a sample of surrounding identities (e.g. content files in the same section).

This commit fixes a flaw in that logic that in some (many...) cases would return a too small sample set.

Fixes #12054

hugolib/content_map_page.go
hugolib/rebuild_test.go

index ae7468b0ae02519e8a7dcd1826384f8a9ee495af..35a2650a1224aac56f9d38dbe608f72709bf5161 100644 (file)
@@ -192,7 +192,7 @@ func (t *pageTrees) collectIdentitiesSurroundingIn(key string, maxSamples int, t
                level := strings.Count(prefix, "/")
                tree.WalkPrefixRaw(prefix, func(s string, n contentNodeI) bool {
                        if level != strings.Count(s, "/") {
-                               return true
+                               return false
                        }
                        n.ForEeachIdentity(func(id identity.Identity) bool {
                                ids = append(ids, id)
index f599d640dc2d6b56f7603e8be94e0bb7a8e6c6bf..d29215a011b5cb01d6294e8117474d41554bc25e 100644 (file)
@@ -261,6 +261,29 @@ func TestRebuilErrorRecovery(t *testing.T) {
        b.EditFileReplaceAll("content/mysection/mysectionbundle/index.md", "{{< foo }}", "{{< foo >}}").Build()
 }
 
+func TestRebuildAddPageListPagesInHome(t *testing.T) {
+       files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+disableLiveReload = true
+-- content/asection/s1.md --
+-- content/p1.md --
+---
+title: "P1"
+weight: 1
+---
+-- layouts/_default/single.html --
+Single: {{ .Title }}|{{ .Content }}|
+-- layouts/index.html --
+Pages: {{ range .RegularPages }}{{ .RelPermalink }}|{{ end }}$
+`
+
+       b := TestRunning(t, files)
+       b.AssertFileContent("public/index.html", "Pages: /p1/|$")
+       b.AddFiles("content/p2.md", ``).Build()
+       b.AssertFileContent("public/index.html", "Pages: /p1/|/p2/|$")
+}
+
 func TestRebuildScopedToOutputFormat(t *testing.T) {
        files := `
 -- hugo.toml --