shithub: hugo

Download patch

ref: f1ed89fec41302ef37ad86348063a7a9be4ef587
parent: 0a0db9cd259bf14bf38f1c954e39ecaa70f26923
author: Bjørn Erik Pedersen <[email protected]>
date: Wed Nov 23 12:26:13 EST 2016

Revise the deprecation strategy

Git users and theme authors two Hugo releases to fix:

1. With a visible warning
2. Then with an ERROR that exits with -1

Fixes #2726

--- a/helpers/general.go
+++ b/helpers/general.go
@@ -250,19 +250,32 @@
 	return &DistinctLogger{m: make(map[string]bool), logger: &jww.FEEDBACK}
 }
 
-// DistinctErrorLog cann be used to avoid spamming the logs with errors.
-var DistinctErrorLog = NewDistinctErrorLogger()
+var (
+	// DistinctErrorLog can be used to avoid spamming the logs with errors.
+	DistinctErrorLog = NewDistinctErrorLogger()
 
+	// DistinctFeedbackLog can be used to avoid spamming the logs with info messages.
+	DistinctFeedbackLog = NewDistinctFeedbackLogger()
+)
+
 // InitLoggers sets up the global distinct loggers.
 func InitLoggers() {
 	DistinctErrorLog = NewDistinctErrorLogger()
 }
 
-// Deprecated logs ERROR logs about a deprecation, but only once for a given set of arguments' values.
-func Deprecated(object, item, alternative string) {
-	//	deprecatedLogger.Printf("%s's %s is deprecated and will be removed in Hugo %s. Use %s instead.", object, item, NextHugoReleaseVersion(), alternative)
-	DistinctErrorLog.Printf("%s's %s is deprecated and will be removed in a future release. Use %s instead.", object, item, alternative)
+// Deprecated informs about a deprecation, but only once for a given set of arguments' values.
+// If the err flag is enabled, it logs as an ERROR (will exit with -1) and the text will
+// point at the next Hugo release.
+// The idea is two remove an item in two Hugo releases to give users and theme authors
+// plenty of time to fix their templates.
+func Deprecated(object, item, alternative string, err bool) {
+	if err {
+		DistinctErrorLog.Printf("%s's %s is deprecated and will be removed in Hugo %s. Use %s instead.", object, item, NextHugoReleaseVersion(), alternative)
 
+	} else {
+		// Make sure the users see this while avoiding build breakage. This will not lead to an os.Exit(-1)
+		DistinctFeedbackLog.Printf("WARNING: %s's %s is deprecated and will be removed in a future release. Use %s instead.", object, item, alternative)
+	}
 }
 
 // SliceToLower goes through the source slice and lowers all values.
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -242,18 +242,18 @@
 }
 
 func (*PageMeta) WordCount() int {
-	helpers.Deprecated("PageMeta", "WordCount", ".WordCount (on Page)")
+	helpers.Deprecated("PageMeta", "WordCount", ".WordCount (on Page)", true)
 	return 0
 }
 
 func (*PageMeta) FuzzyWordCount() int {
-	helpers.Deprecated("PageMeta", "FuzzyWordCount", ".FuzzyWordCount (on Page)")
+	helpers.Deprecated("PageMeta", "FuzzyWordCount", ".FuzzyWordCount (on Page)", true)
 	return 0
 
 }
 
 func (*PageMeta) ReadingTime() int {
-	helpers.Deprecated("PageMeta", "ReadingTime", ".ReadingTime (on Page)")
+	helpers.Deprecated("PageMeta", "ReadingTime", ".ReadingTime (on Page)", true)
 	return 0
 }
 
@@ -1565,7 +1565,7 @@
 
 func (p *Page) RSSlink() template.HTML {
 	// TODO(bep) we cannot have two of these
-	helpers.Deprecated(".Page", "RSSlink", "RSSLink")
+	helpers.Deprecated(".Page", "RSSlink", "RSSLink", false)
 	return p.RSSLink
 }
 
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1270,6 +1270,7 @@
 	} {
 
 		n := &Page{pageInit: &pageInit{}, Kind: KindHome}
+
 		n.RSSLink = "rssLink"
 
 		if !this.assertFunc(n) {
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -245,7 +245,7 @@
 
 // GetParam gets a site parameter value if found, nil if not.
 func (s *SiteInfo) GetParam(key string) interface{} {
-	helpers.Deprecated("SiteInfo", ".GetParam", ".Param")
+	helpers.Deprecated("SiteInfo", ".GetParam", ".Param", false)
 	v := s.Params[strings.ToLower(key)]
 
 	if v == nil {