diff --git a/docs/content/getting-started/configuration.md b/docs/content/getting-started/configuration.md index e821611d690..6034b6eb29e 100644 --- a/docs/content/getting-started/configuration.md +++ b/docs/content/getting-started/configuration.md @@ -245,7 +245,7 @@ disablePathToLower = false enableEmoji = false # Show a placeholder instead of the default value or an empty string if a translation is missing enableMissingTranslationPlaceholders = false -# Regex to use for dates in filenames. Only used with `useFilenameDateAsFallback` +# Regex to use for dates in filenames. filenameDateFallbackPattern = "(?P\\d{4})\\-(?P\\d{2})\\-(?P\\d{2})" # Time format for custom dates in filenames. Only used with `useFilenameDateAsFallback` and must match `filenameDateFallbackPattern` filenameDateFallbackFormat = "2006-01-02" diff --git a/hugolib/page.go b/hugolib/page.go index 14a887bea39..fb9cf309c31 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -1070,16 +1070,21 @@ func (p *Page) update(f interface{}) error { p.Params["draft"] = p.Draft if p.Date.IsZero() && p.s.Cfg.GetBool("useModTimeAsFallback") { + fi, err := p.s.Fs.Source.Stat(filepath.Join(p.s.PathSpec.AbsPathify(p.s.Cfg.GetString("contentDir")), p.File.Path())) if err == nil { + p.s.Log.DEBUG.Printf("using file modification time as fallback for page %s", p.File.Path()) p.Date = fi.ModTime() p.Params["date"] = p.Date } - } else if p.Date.IsZero() && p.s.Cfg.GetString("filenameDateFallbackPattern") != "" { + } + + if p.Date.IsZero() && p.s.Cfg.GetString("filenameDateFallbackPattern") != "" { dateExp := regexp.MustCompile(p.s.Cfg.GetString("filenameDateFallbackPattern")) dateString := dateExp.FindString(p.File.Path()) filenameDate, err := time.Parse(p.s.Cfg.GetString("filenameDateFallbackFormat"), dateString) if err == nil { + p.s.Log.DEBUG.Printf("using filename date as fallback for page %s", p.File.Path()) p.Date = filenameDate p.Params["date"] = p.Date }