ref: be535832f7f4889351df84bad5059bae4db5a95d
parent: be6dfcc4959eac443f92ff51e5ed0fae4c542023
author: bep <[email protected]>
date: Wed May 27 23:19:59 EDT 2015
Add IsHome To determine if a page is the "Home Page" has inspired lots of creativity in the template department. This commit makes it simpler: IsHome will tell the truth.
--- a/hugolib/node.go
+++ b/hugolib/node.go
@@ -33,6 +33,7 @@
Lastmod time.Time
Sitemap Sitemap
URLPath
+ IsHome bool
paginator *Pager
paginatorInit sync.Once
scratch *Scratch
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -11,6 +11,7 @@
"github.com/spf13/cast"
"github.com/spf13/hugo/helpers"
"github.com/spf13/viper"
+ "github.com/stretchr/testify/assert"
)
var EMPTY_PAGE = ""
@@ -368,6 +369,8 @@
if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
}
+
+ assert.False(t, p.IsHome)
checkPageTitle(t, p, "Simple")
checkPageContent(t, p, "<p>Simple Page</p>\n")
checkPageSummary(t, p, "Simple Page")
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -1233,6 +1233,7 @@
func (s *Site) newHomeNode() *Node {
n := s.NewNode()
n.Title = n.Site.Title
+ n.IsHome = true
s.setURLs(n, "/")
n.Data["Pages"] = s.Pages
return n
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -16,6 +16,7 @@
"github.com/spf13/hugo/target"
"github.com/spf13/hugo/tpl"
"github.com/spf13/viper"
+ "github.com/stretchr/testify/assert"
)
const (
@@ -417,6 +418,10 @@
{filepath.FromSlash("404.html"), "Page Not Found"},
{filepath.FromSlash("index.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n<root>RSS</root>"},
{filepath.FromSlash("sitemap.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n<root>SITEMAP</root>"},
+ }
+
+ for _, p := range s.Pages {
+ assert.False(t, p.IsHome)
}
for _, test := range tests {