Skip to content

Commit

Permalink
Add IsHome
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bep committed May 28, 2015
1 parent be6dfcc commit be53583
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions hugolib/node.go
Expand Up @@ -33,6 +33,7 @@ type Node struct {
Lastmod time.Time
Sitemap Sitemap
URLPath
IsHome bool
paginator *Pager
paginatorInit sync.Once
scratch *Scratch
Expand Down
3 changes: 3 additions & 0 deletions hugolib/page_test.go
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/cast"
"github.com/spf13/hugo/helpers"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)

var EMPTY_PAGE = ""
Expand Down Expand Up @@ -368,6 +369,8 @@ func TestCreateNewPage(t *testing.T) {
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")
Expand Down
1 change: 1 addition & 0 deletions hugolib/site.go
Expand Up @@ -1233,6 +1233,7 @@ func (s *Site) RenderSectionLists() error {
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
Expand Down
5 changes: 5 additions & 0 deletions hugolib/site_test.go
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/spf13/hugo/target"
"github.com/spf13/hugo/tpl"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)

const (
Expand Down Expand Up @@ -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>"},
}

for _, p := range s.Pages {
assert.False(t, p.IsHome)
}

for _, test := range tests {
file, err := hugofs.DestinationFS.Open(test.doc)
if err != nil {
Expand Down

1 comment on commit be53583

@RickCogley
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bep thanks! That's much easier.

Please sign in to comment.