Repository: gohugoio/hugo (language: go)

Issue:
server: Newly created files are not rendered on refresh
When you start server, and then create a page, it won't appear in rendered pages list. Hugo notices the change, runs rebuild, but the lists stay the same. If you restart hugo, new page appears in the list.

Also, in some more complicated scenarios, new pages do appear in the lists, but they have empty content (empty title, empty content), even though it is not empty.


Discussion / hints:
I have tested this without any issues (took it for a spin now), so you need to be more specific.
Okay, take [this example site](https://github.com/TiGR/hugo-testing/tree/broken-getterms-issue).

1. Run hugo server
2. Open the server in browser, you'll see a list of pages, there is only one page, Test Page.
3. Make a new page (for instance, create a file `content/test-page-2/index.md`), fill it with some test content
4. Notice hugo runs rerender
5. Check the browser, see the list still showing only one page
6. Restart hugo
7. Check the browser and see that there is that new page in the list.

In hugo 0.122 everything works as expected.

Fix patch:
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index d9cbddfba62..37d62256148 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -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)


Test patch:
diff --git a/hugolib/rebuild_test.go b/hugolib/rebuild_test.go
index 6e43a4570d2..7e2709f50e9 100644
--- a/hugolib/rebuild_test.go
+++ b/hugolib/rebuild_test.go
@@ -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 --