mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
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
This commit is contained in:
parent
0a0db9cd25
commit
f1ed89fec4
4 changed files with 25 additions and 11 deletions
|
@ -250,19 +250,32 @@ func NewDistinctFeedbackLogger() *DistinctLogger {
|
||||||
return &DistinctLogger{m: make(map[string]bool), logger: &jww.FEEDBACK}
|
return &DistinctLogger{m: make(map[string]bool), logger: &jww.FEEDBACK}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DistinctErrorLog cann be used to avoid spamming the logs with errors.
|
var (
|
||||||
var DistinctErrorLog = NewDistinctErrorLogger()
|
// 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.
|
// InitLoggers sets up the global distinct loggers.
|
||||||
func InitLoggers() {
|
func InitLoggers() {
|
||||||
DistinctErrorLog = NewDistinctErrorLogger()
|
DistinctErrorLog = NewDistinctErrorLogger()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated logs ERROR logs about a deprecation, but only once for a given set of arguments' values.
|
// Deprecated informs about a deprecation, but only once for a given set of arguments' values.
|
||||||
func Deprecated(object, item, alternative string) {
|
// If the err flag is enabled, it logs as an ERROR (will exit with -1) and the text will
|
||||||
// deprecatedLogger.Printf("%s's %s is deprecated and will be removed in Hugo %s. Use %s instead.", object, item, NextHugoReleaseVersion(), alternative)
|
// point at the next Hugo release.
|
||||||
DistinctErrorLog.Printf("%s's %s is deprecated and will be removed in a future release. Use %s instead.", object, item, alternative)
|
// 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.
|
// SliceToLower goes through the source slice and lowers all values.
|
||||||
|
|
|
@ -242,18 +242,18 @@ type PageMeta struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PageMeta) WordCount() int {
|
func (*PageMeta) WordCount() int {
|
||||||
helpers.Deprecated("PageMeta", "WordCount", ".WordCount (on Page)")
|
helpers.Deprecated("PageMeta", "WordCount", ".WordCount (on Page)", true)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PageMeta) FuzzyWordCount() int {
|
func (*PageMeta) FuzzyWordCount() int {
|
||||||
helpers.Deprecated("PageMeta", "FuzzyWordCount", ".FuzzyWordCount (on Page)")
|
helpers.Deprecated("PageMeta", "FuzzyWordCount", ".FuzzyWordCount (on Page)", true)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*PageMeta) ReadingTime() int {
|
func (*PageMeta) ReadingTime() int {
|
||||||
helpers.Deprecated("PageMeta", "ReadingTime", ".ReadingTime (on Page)")
|
helpers.Deprecated("PageMeta", "ReadingTime", ".ReadingTime (on Page)", true)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1565,7 +1565,7 @@ func (p *Page) Hugo() *HugoInfo {
|
||||||
|
|
||||||
func (p *Page) RSSlink() template.HTML {
|
func (p *Page) RSSlink() template.HTML {
|
||||||
// TODO(bep) we cannot have two of these
|
// TODO(bep) we cannot have two of these
|
||||||
helpers.Deprecated(".Page", "RSSlink", "RSSLink")
|
helpers.Deprecated(".Page", "RSSlink", "RSSLink", false)
|
||||||
return p.RSSLink
|
return p.RSSLink
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1270,6 +1270,7 @@ func TestIndexPageSimpleMethods(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
|
|
||||||
n := &Page{pageInit: &pageInit{}, Kind: KindHome}
|
n := &Page{pageInit: &pageInit{}, Kind: KindHome}
|
||||||
|
|
||||||
n.RSSLink = "rssLink"
|
n.RSSLink = "rssLink"
|
||||||
|
|
||||||
if !this.assertFunc(n) {
|
if !this.assertFunc(n) {
|
||||||
|
|
|
@ -245,7 +245,7 @@ func (s *SiteInfo) Param(key interface{}) (interface{}, error) {
|
||||||
|
|
||||||
// GetParam gets a site parameter value if found, nil if not.
|
// GetParam gets a site parameter value if found, nil if not.
|
||||||
func (s *SiteInfo) GetParam(key string) interface{} {
|
func (s *SiteInfo) GetParam(key string) interface{} {
|
||||||
helpers.Deprecated("SiteInfo", ".GetParam", ".Param")
|
helpers.Deprecated("SiteInfo", ".GetParam", ".Param", false)
|
||||||
v := s.Params[strings.ToLower(key)]
|
v := s.Params[strings.ToLower(key)]
|
||||||
|
|
||||||
if v == nil {
|
if v == nil {
|
||||||
|
|
Loading…
Reference in a new issue