shithub: hugo

Download patch

ref: 7cc637e97a596336d1c64c203cb089e9de84ec45
parent: 503fb29953d4cd57ec3a188f529c11d41798d772
author: Bjørn Erik Pedersen <[email protected]>
date: Wed Nov 9 06:09:16 EST 2016

node to page: Do not create section node for root

Because that will overwrite the home page, which is bad.

Updates #2297

--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -461,6 +461,13 @@
 		sectionPages := s.findPagesByNodeType(NodeSection)
 		if len(sectionPages) < len(s.Sections) {
 			for name, section := range s.Sections {
+				// A section may be created for the root content folder if a
+				// content file is placed there.
+				// We cannot create a section node for that, because
+				// that would overwrite the home page.
+				if name == "" {
+					continue
+				}
 				foundSection := false
 				for _, sectionPage := range sectionPages {
 					if sectionPage.sections[0] == name {
--- a/hugolib/hugo_sites_test.go
+++ b/hugolib/hugo_sites_test.go
@@ -217,11 +217,11 @@
 
 	assert.Equal(t, "en", enSite.Language.Lang)
 
-	if len(enSite.Pages) != 3 {
-		t.Fatal("Expected 3 english pages")
+	if len(enSite.Pages) != 4 {
+		t.Fatal("Expected 4 english pages")
 	}
-	assert.Len(t, enSite.Source.Files(), 13, "should have 13 source files")
-	assert.Len(t, enSite.AllPages, 8, "should have 8 total pages (including translations)")
+	assert.Len(t, enSite.Source.Files(), 14, "should have 13 source files")
+	assert.Len(t, enSite.AllPages, 9, "should have 8 total pages (including translations)")
 
 	doc1en := enSite.Pages[0]
 	permalink, err := doc1en.Permalink()
@@ -278,7 +278,7 @@
 
 	assert.Equal(t, "fr", frSite.Language.Lang)
 	assert.Len(t, frSite.Pages, 3, "should have 3 pages")
-	assert.Len(t, frSite.AllPages, 8, "should have 8 total pages (including translations)")
+	assert.Len(t, frSite.AllPages, 9, "should have 8 total pages (including translations)")
 
 	for _, frenchPage := range frSite.Pages {
 		assert.Equal(t, "fr", frenchPage.Lang())
@@ -387,7 +387,7 @@
 	enSite := sites.Sites[0]
 	frSite := sites.Sites[1]
 
-	require.Len(t, enSite.Pages, 3)
+	require.Len(t, enSite.Pages, 4)
 	require.Len(t, frSite.Pages, 3)
 
 	// Verify translations
@@ -414,7 +414,7 @@
 			nil,
 			[]fsnotify.Event{{Name: "content/sect/doc2.en.md", Op: fsnotify.Remove}},
 			func(t *testing.T) {
-				require.Len(t, enSite.Pages, 2, "1 en removed")
+				require.Len(t, enSite.Pages, 3, "1 en removed")
 
 				// Check build stats
 				require.Equal(t, 1, enSite.draftCount, "Draft")
@@ -437,8 +437,8 @@
 				{Name: "content/new1.fr.md", Op: fsnotify.Create},
 			},
 			func(t *testing.T) {
-				require.Len(t, enSite.Pages, 4)
-				require.Len(t, enSite.AllPages, 10)
+				require.Len(t, enSite.Pages, 5)
+				require.Len(t, enSite.AllPages, 11)
 				require.Len(t, frSite.Pages, 4)
 				require.Equal(t, "new_fr_1", frSite.Pages[3].Title)
 				require.Equal(t, "new_en_2", enSite.Pages[0].Title)
@@ -457,7 +457,7 @@
 			},
 			[]fsnotify.Event{{Name: "content/sect/doc1.en.md", Op: fsnotify.Write}},
 			func(t *testing.T) {
-				require.Len(t, enSite.Pages, 4)
+				require.Len(t, enSite.Pages, 5)
 				doc1 := readDestination(t, "public/en/sect/doc1-slug/index.html")
 				require.True(t, strings.Contains(doc1, "CHANGED"), doc1)
 
@@ -475,7 +475,7 @@
 				{Name: "content/new1.en.md", Op: fsnotify.Rename},
 			},
 			func(t *testing.T) {
-				require.Len(t, enSite.Pages, 4, "Rename")
+				require.Len(t, enSite.Pages, 5, "Rename")
 				require.Equal(t, "new_en_1", enSite.Pages[1].Title)
 				rendered := readDestination(t, "public/en/new1renamed/index.html")
 				require.True(t, strings.Contains(rendered, "new_en_1"), rendered)
@@ -490,8 +490,8 @@
 			},
 			[]fsnotify.Event{{Name: "layouts/_default/single.html", Op: fsnotify.Write}},
 			func(t *testing.T) {
-				require.Len(t, enSite.Pages, 4)
-				require.Len(t, enSite.AllPages, 10)
+				require.Len(t, enSite.Pages, 5)
+				require.Len(t, enSite.AllPages, 11)
 				require.Len(t, frSite.Pages, 4)
 				doc1 := readDestination(t, "public/en/sect/doc1-slug/index.html")
 				require.True(t, strings.Contains(doc1, "Template Changed"), doc1)
@@ -507,8 +507,8 @@
 			},
 			[]fsnotify.Event{{Name: "i18n/fr.yaml", Op: fsnotify.Write}},
 			func(t *testing.T) {
-				require.Len(t, enSite.Pages, 4)
-				require.Len(t, enSite.AllPages, 10)
+				require.Len(t, enSite.Pages, 5)
+				require.Len(t, enSite.AllPages, 11)
 				require.Len(t, frSite.Pages, 4)
 				docEn := readDestination(t, "public/en/sect/doc1-slug/index.html")
 				require.True(t, strings.Contains(docEn, "Hello"), "No Hello")
@@ -531,8 +531,8 @@
 				{Name: "layouts/shortcodes/shortcode.html", Op: fsnotify.Write},
 			},
 			func(t *testing.T) {
-				require.Len(t, enSite.Pages, 4)
-				require.Len(t, enSite.AllPages, 10)
+				require.Len(t, enSite.Pages, 5)
+				require.Len(t, enSite.AllPages, 11)
 				require.Len(t, frSite.Pages, 4)
 				assertFileContent(t, "public/fr/sect/doc1/index.html", true, "Single", "Modified Shortcode: Salut")
 				assertFileContent(t, "public/en/sect/doc1-slug/index.html", true, "Single", "Modified Shortcode: Hello")
@@ -626,7 +626,7 @@
 	require.Len(t, homeEn.Translations(), 4)
 	require.Equal(t, "sv", homeEn.Translations()[0].Lang())
 
-	require.Len(t, enSite.Pages, 3)
+	require.Len(t, enSite.Pages, 4)
 	require.Len(t, frSite.Pages, 3)
 
 	// Veriy Swedish site
@@ -1026,6 +1026,14 @@
 
 	// Sources
 	sources := []source.ByteSource{
+		{Name: filepath.FromSlash("root.en.md"), Content: []byte(`---
+title: root
+weight: 10000
+slug: root
+publishdate: "2000-01-01"
+---
+# root
+`)},
 		{Name: filepath.FromSlash("sect/doc1.en.md"), Content: []byte(`---
 title: doc1
 weight: 1