Add automatic page date fallback
authorVincent Batoufflet <vincent@batoufflet.info>
Mon, 27 Jun 2016 15:07:34 +0000 (17:07 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 28 Jun 2016 21:50:50 +0000 (23:50 +0200)
Closes #2239

hugolib/page.go

index 198f7ba14ce9e7e6b201507c9138515cf5a10f7a..000551ec3a4219c02e39747cbf0c0901bbd8177e 100644 (file)
@@ -663,6 +663,13 @@ func (p *Page) update(f interface{}) error {
                p.Draft = !*published
        }
 
+       if p.Date.IsZero() {
+               fi, err := hugofs.Source().Stat(filepath.Join(helpers.AbsPathify(viper.GetString("ContentDir")), p.File.Path()))
+               if err == nil {
+                       p.Date = fi.ModTime()
+               }
+       }
+
        if p.Lastmod.IsZero() {
                p.Lastmod = p.Date
        }