diff --git a/hugolib/node.go b/hugolib/node.go index 9be215058..7606e8896 100644 --- a/hugolib/node.go +++ b/hugolib/node.go @@ -30,6 +30,7 @@ type Node struct { Keywords []string Params map[string]interface{} Date time.Time + Lastmod time.Time Sitemap Sitemap URLPath paginator *Pager diff --git a/hugolib/page.go b/hugolib/page.go index 56a9ff16a..fd3bddcdb 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -473,6 +473,11 @@ func (p *Page) update(f interface{}) error { if err != nil { jww.ERROR.Printf("Failed to parse date '%v' in page %s", v, p.File.Path()) } + case "lastmod": + p.Lastmod, err = cast.ToTimeE(v) + if err != nil { + jww.ERROR.Printf("Failed to parse lastmod '%v' in page %s", v, p.File.Path()) + } case "publishdate", "pubdate": p.PublishDate, err = cast.ToTimeE(v) if err != nil { @@ -524,6 +529,11 @@ func (p *Page) update(f interface{}) error { } } } + + if p.Lastmod.IsZero() { + p.Lastmod = p.Date + } + return nil } diff --git a/hugolib/site.go b/hugolib/site.go index 2018df4bb..45912abcd 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -1065,6 +1065,7 @@ func (s *Site) newTaxonomyNode(t taxRenderInfo) (*Node, string) { s.setURLs(n, base) if len(t.pages) > 0 { n.Date = t.pages[0].Page.Date + n.Lastmod = t.pages[0].Page.Lastmod } n.Data[t.singular] = t.pages n.Data["Singular"] = t.singular @@ -1110,6 +1111,7 @@ func taxonomyRenderer(s *Site, taxes <-chan taxRenderInfo, results chan<- error, taxonomyPagerNode.paginator = pager if pager.TotalPages() > 0 { taxonomyPagerNode.Date = pager.Pages()[0].Date + taxonomyPagerNode.Lastmod = pager.Pages()[0].Lastmod } pageNumber := i + 1 htmlBase := fmt.Sprintf("/%s/%s/%d", base, paginatePath, pageNumber) @@ -1168,6 +1170,7 @@ func (s *Site) newSectionListNode(section string, data WeightedPages) *Node { } s.setURLs(n, section) n.Date = data[0].Page.Date + n.Lastmod = data[0].Page.Lastmod n.Data["Pages"] = data.Pages() return n @@ -1205,6 +1208,7 @@ func (s *Site) RenderSectionLists() error { sectionPagerNode.paginator = pager if pager.TotalPages() > 0 { sectionPagerNode.Date = pager.Pages()[0].Date + sectionPagerNode.Lastmod = pager.Pages()[0].Lastmod } pageNumber := i + 1 htmlBase := fmt.Sprintf("/%s/%s/%d", section, paginatePath, pageNumber) @@ -1262,6 +1266,7 @@ func (s *Site) RenderHomePage() error { homePagerNode.paginator = pager if pager.TotalPages() > 0 { homePagerNode.Date = pager.Pages()[0].Date + homePagerNode.Lastmod = pager.Pages()[0].Lastmod } pageNumber := i + 1 htmlBase := fmt.Sprintf("/%s/%d", paginatePath, pageNumber) @@ -1282,6 +1287,7 @@ func (s *Site) RenderHomePage() error { n.Data["Pages"] = s.Pages[:high] if len(s.Pages) > 0 { n.Date = s.Pages[0].Date + n.Lastmod = s.Pages[0].Lastmod } rssLayouts := []string{"rss.xml", "_default/rss.xml", "_internal/_default/rss.xml"} @@ -1317,6 +1323,7 @@ func (s *Site) RenderSitemap() error { page := &Page{} page.Date = s.Info.LastChange + page.Lastmod = s.Info.LastChange page.Site = &s.Info page.URL = "/"