node to page: Handle aliases on home page etc.
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Nov 2016 10:01:58 +0000 (11:01 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 22 Nov 2016 08:57:03 +0000 (09:57 +0100)
Updates #2297

hugolib/node_as_page_test.go
hugolib/site_render.go

index 083bdc30eef2864d826bce05f2da815376c9e929..b871c3016ebe853593d1bb2814f2349089247f3f 100644 (file)
@@ -325,8 +325,6 @@ categories:  [
 }
 
 func TestNodesWithMenu(t *testing.T) {
-       //jww.SetStdoutThreshold(jww.LevelDebug)
-       //defer jww.SetStdoutThreshold(jww.LevelFatal)
        testCommonResetState()
 
        writeLayoutsForNodeAsPageTests(t)
@@ -353,6 +351,35 @@ menu:
 
 }
 
+func TestNodesWithAlias(t *testing.T) {
+       //jww.SetStdoutThreshold(jww.LevelDebug)
+       //defer jww.SetStdoutThreshold(jww.LevelFatal)
+       testCommonResetState()
+
+       writeLayoutsForNodeAsPageTests(t)
+       writeRegularPagesForNodeAsPageTests(t)
+
+       writeSource(t, filepath.Join("content", "_index.md"), `---
+title: Home With Alias
+aliases:
+    - /my/new/home.html
+---
+`)
+
+       viper.Set("paginate", 1)
+       viper.Set("title", "Hugo Rocks!")
+
+       s := newSiteDefaultLang()
+
+       if err := buildAndRenderSite(s); err != nil {
+               t.Fatalf("Failed to build site: %s", err)
+       }
+
+       assertFileContent(t, filepath.Join("public", "index.html"), true, "Home With Alias")
+       assertFileContent(t, filepath.Join("public", "my", "new", "home.html"), true, "content=\"0; url=/")
+
+}
+
 func writeRegularPagesForNodeAsPageTests(t *testing.T) {
        writeRegularPagesForNodeAsPageTestsWithLang(t, "")
 }
index 8777d91a707ae1aa7eddf4f651b94b0fdc3305b6..9a65987caf8ae92ba7fbb3582301370596b35308 100644 (file)
@@ -238,9 +238,8 @@ func (s *Site) renderRobotsTXT() error {
 }
 
 // renderAliases renders shell pages that simply have a redirect in the header.
-// TODO(bep) np aliases of node types
 func (s *Site) renderAliases() error {
-       for _, p := range s.Pages {
+       for _, p := range s.Nodes {
                if len(p.Aliases) == 0 {
                        continue
                }