diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-04-05 11:05:25 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-04-05 11:20:09 +0200 |
commit | 1d9dde82a0577d93eea8ed0a7ec0b4ae3068eb19 (patch) | |
tree | d8cdf2376e9ee7ffbb52e8af381f219887b39b22 | |
parent | 87b16abd93ff60acd245776d5b0d914fd580c259 (diff) |
hugolib: Fix default date assignment for sections
See #5784
-rw-r--r-- | hugolib/page_test.go | 30 | ||||
-rw-r--r-- | hugolib/site_sections.go | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 570d09ac6..6d9d337eb 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -448,7 +448,7 @@ categories: ["cool stuff"] b := newTestSitesBuilder(t) b.WithSimpleConfigFile().WithContent("page.md", pageContent) - b.WithSimpleConfigFile().WithContent("blog/page.md", pageContent) + b.WithContent("blog/page.md", pageContent) b.CreateSites().Build(BuildCfg{}) @@ -470,6 +470,34 @@ categories: ["cool stuff"] } +func TestPageDatesSections(t *testing.T) { + t.Parallel() + assert := assert.New(t) + + b := newTestSitesBuilder(t) + b.WithSimpleConfigFile().WithContent("no-index/page.md", ` +--- +title: Page +date: 2017-01-15 +--- +`) + b.WithSimpleConfigFile().WithContent("with-index-no-date/_index.md", `--- +title: No Date +--- + +`) + + b.CreateSites().Build(BuildCfg{}) + + assert.Equal(1, len(b.H.Sites)) + s := b.H.Sites[0] + + assert.Equal(2017, s.getPage("/").Date().Year()) + assert.Equal(2017, s.getPage("/no-index").Date().Year()) + assert.True(s.getPage("/with-index-no-date").Date().IsZero()) + +} + func TestCreateNewPage(t *testing.T) { t.Parallel() assertFunc := func(t *testing.T, ext string, pages page.Pages) { diff --git a/hugolib/site_sections.go b/hugolib/site_sections.go index d383e6389..9090c3ede 100644 --- a/hugolib/site_sections.go +++ b/hugolib/site_sections.go @@ -162,6 +162,7 @@ func (s *Site) assembleSections() pageStatePages { if currentSection != nil { // A new section currentSection.setPages(children) + currentSection.m.Dates = *dates } currentSection = p @@ -176,6 +177,7 @@ func (s *Site) assembleSections() pageStatePages { p.parent = currentSection children = append(children, p) dates.UpdateDateAndLastmodIfAfter(p) + return false }) |