Skip to content

Commit 9b5f786

Browse files
committed
Deprecate kind, lang, and path from front matter
These were added to the page meta object when we implemented "pages from data", but were not meant to be used in front matter. That is not supported, so we might as well add validation. Fixes #12484
1 parent e6feb9e commit 9b5f786

File tree

9 files changed

+57
-13
lines changed

9 files changed

+57
-13
lines changed

commands/commandeer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func (r *rootCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
448448
return err
449449
}
450450
// Set up the global logger early to allow info deprecations during config load.
451-
loggers.InitGlobalLogger(r.logger.Level(), false)
451+
loggers.SetGlobalLogger(r.logger)
452452

453453
r.changesFromBuild = make(chan []identity.Identity, 10)
454454

common/hugo/hugo.go

+9
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,15 @@ func Deprecate(item, alternative string, version string) {
414414
DeprecateLevel(item, alternative, version, level)
415415
}
416416

417+
// DeprecateLevelMin informs about a deprecation starting at the given version, but with a minimum log level.
418+
func DeprecateLevelMin(item, alternative string, version string, minLevel logg.Level) {
419+
level := deprecationLogLevelFromVersion(version)
420+
if level < minLevel {
421+
level = minLevel
422+
}
423+
DeprecateLevel(item, alternative, version, level)
424+
}
425+
417426
// DeprecateLevel informs about a deprecation logging at the given level.
418427
func DeprecateLevel(item, alternative, version string, level logg.Level) {
419428
var msg string

common/loggers/loggerglobal.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ import (
2121
"github.com/bep/logg"
2222
)
2323

24-
func InitGlobalLogger(level logg.Level, panicOnWarnings bool) {
24+
// SetGlobalLogger sets the global logger.
25+
// This is used in a few places in Hugo, e.g. deprecated functions.
26+
func SetGlobalLogger(logger Logger) {
27+
logMu.Lock()
28+
defer logMu.Unlock()
29+
log = logger
30+
}
31+
32+
func initGlobalLogger(level logg.Level, panicOnWarnings bool) {
2533
logMu.Lock()
2634
defer logMu.Unlock()
2735
var logHookLast func(e *logg.Entry) error
@@ -50,5 +58,5 @@ func Log() Logger {
5058
var log Logger
5159

5260
func init() {
53-
InitGlobalLogger(logg.LevelWarn, false)
61+
initGlobalLogger(logg.LevelWarn, false)
5462
}

config/allconfig/load.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func LoadConfig(d ConfigSourceDescriptor) (*Configs, error) {
9191
return nil, fmt.Errorf("failed to init config: %w", err)
9292
}
9393

94-
loggers.InitGlobalLogger(d.Logger.Level(), configs.Base.PanicOnWarning)
94+
loggers.SetGlobalLogger(d.Logger)
9595

9696
return configs, nil
9797
}

config/privacy/privacyConfig_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ respectDoNotTrack = true
3636
[privacy.instagram]
3737
disable = true
3838
simple = true
39-
[privacy.twitter]
40-
disable = true
41-
enableDNT = true
42-
simple = true
4339
[privacy.x]
4440
disable = true
4541
enableDNT = true
@@ -63,8 +59,8 @@ simple = true
6359
got := []bool{
6460
pc.Disqus.Disable, pc.GoogleAnalytics.Disable,
6561
pc.GoogleAnalytics.RespectDoNotTrack, pc.Instagram.Disable,
66-
pc.Instagram.Simple, pc.Twitter.Disable, pc.Twitter.EnableDNT,
67-
pc.Twitter.Simple, pc.Vimeo.Disable, pc.Vimeo.EnableDNT, pc.Vimeo.Simple,
62+
pc.Instagram.Simple,
63+
pc.Vimeo.Disable, pc.Vimeo.EnableDNT, pc.Vimeo.Simple,
6864
pc.YouTube.PrivacyEnhanced, pc.YouTube.Disable, pc.X.Disable, pc.X.EnableDNT,
6965
pc.X.Simple,
7066
}

hugolib/page__meta.go

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222
"time"
2323

24+
"github.com/bep/logg"
2425
"github.com/gobuffalo/flect"
2526
"github.com/gohugoio/hugo/langs"
2627
"github.com/gohugoio/hugo/markup/converter"
@@ -32,6 +33,7 @@ import (
3233

3334
"github.com/gohugoio/hugo/common/constants"
3435
"github.com/gohugoio/hugo/common/hashing"
36+
"github.com/gohugoio/hugo/common/hugo"
3537
"github.com/gohugoio/hugo/common/loggers"
3638
"github.com/gohugoio/hugo/common/maps"
3739
"github.com/gohugoio/hugo/common/paths"
@@ -486,6 +488,11 @@ params:
486488
continue
487489
}
488490

491+
if loki == "path" || loki == "kind" || loki == "lang" {
492+
// See issue 12484.
493+
hugo.DeprecateLevelMin(loki+" in front matter", "", "v0.144.0", logg.LevelWarn)
494+
}
495+
489496
switch loki {
490497
case "title":
491498
pcfg.Title = cast.ToString(v)

hugolib/page_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -1942,3 +1942,29 @@ Hugo: h-Home|
19421942
`,
19431943
)
19441944
}
1945+
1946+
// See #12484
1947+
func TestPageFrontMatterDeprecatePathKindLang(t *testing.T) {
1948+
// This cannot be parallel as it depends on output from the global logger.
1949+
1950+
files := `
1951+
-- hugo.toml --
1952+
disableKinds = ["taxonomy", "term", "home", "section"]
1953+
-- content/p1.md --
1954+
---
1955+
title: "p1"
1956+
kind: "page"
1957+
lang: "en"
1958+
path: "mypath"
1959+
---
1960+
-- layouts/_default/single.html --
1961+
Title: {{ .Title }}
1962+
`
1963+
b := Test(t, files, TestOptWarn())
1964+
b.AssertFileContent("public/mypath/index.html", "p1")
1965+
b.AssertLogContains(
1966+
"deprecated: kind in front matter was deprecated",
1967+
"deprecated: lang in front matter was deprecated",
1968+
"deprecated: path in front matter was deprecated",
1969+
)
1970+
}

hugolib/testhelpers_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,6 @@ disable = false
260260
respectDoNotTrack = true
261261
[privacy.instagram]
262262
simple = true
263-
[privacy.twitter]
264-
enableDNT = true
265263
[privacy.x]
266264
enableDNT = true
267265
[privacy.vimeo]

tpl/tplimpl/shortcodes_integration_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
func TestCommentShortcode(t *testing.T) {
25-
t.Parallel()
25+
// This cannot be parallel as it depends on output from the global logger.
2626

2727
files := `
2828
-- hugo.toml --

0 commit comments

Comments
 (0)