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.
This commit is contained in:
bep 2015-05-28 03:19:59 +02:00
parent be6dfcc495
commit be535832f7
4 changed files with 10 additions and 0 deletions

View file

@ -33,6 +33,7 @@ type Node struct {
Lastmod time.Time Lastmod time.Time
Sitemap Sitemap Sitemap Sitemap
URLPath URLPath
IsHome bool
paginator *Pager paginator *Pager
paginatorInit sync.Once paginatorInit sync.Once
scratch *Scratch scratch *Scratch

View file

@ -11,6 +11,7 @@ import (
"github.com/spf13/cast" "github.com/spf13/cast"
"github.com/spf13/hugo/helpers" "github.com/spf13/hugo/helpers"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/stretchr/testify/assert"
) )
var EMPTY_PAGE = "" var EMPTY_PAGE = ""
@ -368,6 +369,8 @@ func TestCreateNewPage(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Unable to create a page with frontmatter and body content: %s", err) t.Fatalf("Unable to create a page with frontmatter and body content: %s", err)
} }
assert.False(t, p.IsHome)
checkPageTitle(t, p, "Simple") checkPageTitle(t, p, "Simple")
checkPageContent(t, p, "<p>Simple Page</p>\n") checkPageContent(t, p, "<p>Simple Page</p>\n")
checkPageSummary(t, p, "Simple Page") checkPageSummary(t, p, "Simple Page")

View file

@ -1233,6 +1233,7 @@ func (s *Site) RenderSectionLists() error {
func (s *Site) newHomeNode() *Node { func (s *Site) newHomeNode() *Node {
n := s.NewNode() n := s.NewNode()
n.Title = n.Site.Title n.Title = n.Site.Title
n.IsHome = true
s.setURLs(n, "/") s.setURLs(n, "/")
n.Data["Pages"] = s.Pages n.Data["Pages"] = s.Pages
return n return n

View file

@ -16,6 +16,7 @@ import (
"github.com/spf13/hugo/target" "github.com/spf13/hugo/target"
"github.com/spf13/hugo/tpl" "github.com/spf13/hugo/tpl"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/stretchr/testify/assert"
) )
const ( const (
@ -419,6 +420,10 @@ func doTest404ShouldAlwaysHaveUglyUrls(t *testing.T, uglyURLs bool) {
{filepath.FromSlash("sitemap.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>\n<root>SITEMAP</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 { for _, test := range tests {
file, err := hugofs.DestinationFS.Open(test.doc) file, err := hugofs.DestinationFS.Open(test.doc)
if err != nil { if err != nil {