hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 3882e7ceaf818e295fdc652377af914bb60faf7f
parent be534a865ddceb8f95ba20e072f136c842176623
Author: Juan B. Rodriguez <jbrodriguez@gmail.com>
Date:   Thu, 14 May 2015 15:06:36 -0500

Add Lastmod field

Create new field in Node
Update Page to look for lastmod field in the front matter. If not present, then assign Date to Lastmod
Update Site, to assign a value to Lastmod (based on the same logic used for Date)

Fixes #733

Diffstat:
Mhugolib/node.go | 1+
Mhugolib/page.go | 10++++++++++
Mhugolib/site.go | 7+++++++
3 files changed, 18 insertions(+), 0 deletions(-)
diff --git 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
@@ -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
@@ -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 = "/"