mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
1c97095ac0
commit
bec9b80d95
4 changed files with 66 additions and 7 deletions
|
@ -173,6 +173,7 @@ type Logger interface {
|
||||||
WarnCommand(command string) logg.LevelLogger
|
WarnCommand(command string) logg.LevelLogger
|
||||||
Warnf(format string, v ...any)
|
Warnf(format string, v ...any)
|
||||||
Warnln(v ...any)
|
Warnln(v ...any)
|
||||||
|
Deprecatef(fail bool, format string, v ...any)
|
||||||
}
|
}
|
||||||
|
|
||||||
type logAdapter struct {
|
type logAdapter struct {
|
||||||
|
@ -297,6 +298,15 @@ func (l *logAdapter) sprint(v ...any) string {
|
||||||
return strings.TrimRight(fmt.Sprintln(v...), "\n")
|
return strings.TrimRight(fmt.Sprintln(v...), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *logAdapter) Deprecatef(fail bool, format string, v ...any) {
|
||||||
|
format = "DEPRECATED: " + format
|
||||||
|
if fail {
|
||||||
|
l.errorl.Logf(format, v...)
|
||||||
|
} else {
|
||||||
|
l.warnl.Logf(format, v...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type logWriter struct {
|
type logWriter struct {
|
||||||
l logg.LevelLogger
|
l logg.LevelLogger
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,12 +240,13 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
|
||||||
disabledKinds := make(map[string]bool)
|
disabledKinds := make(map[string]bool)
|
||||||
for _, kind := range c.DisableKinds {
|
for _, kind := range c.DisableKinds {
|
||||||
kind = strings.ToLower(kind)
|
kind = strings.ToLower(kind)
|
||||||
if kind == "taxonomyterm" {
|
if newKind := kinds.IsDeprecatedAndReplacedWith(kind); newKind != "" {
|
||||||
|
logger.Deprecatef(false, "Kind %q used in disableKinds is deprecated, use %q instead.", kind, newKind)
|
||||||
// Legacy config.
|
// Legacy config.
|
||||||
kind = "taxonomy"
|
kind = newKind
|
||||||
}
|
}
|
||||||
if kinds.GetKindAny(kind) == "" {
|
if kinds.GetKindAny(kind) == "" {
|
||||||
logger.Warnf("Unknown kind %q in disableKinds", kind)
|
logger.Warnf("Unknown kind %q in disableKinds configuration.", kind)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
disabledKinds[kind] = true
|
disabledKinds[kind] = true
|
||||||
|
@ -254,9 +255,17 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
|
||||||
isRssDisabled := disabledKinds["rss"]
|
isRssDisabled := disabledKinds["rss"]
|
||||||
outputFormats := c.OutputFormats.Config
|
outputFormats := c.OutputFormats.Config
|
||||||
for kind, formats := range c.Outputs {
|
for kind, formats := range c.Outputs {
|
||||||
|
if newKind := kinds.IsDeprecatedAndReplacedWith(kind); newKind != "" {
|
||||||
|
logger.Deprecatef(false, "Kind %q used in outputs configuration is deprecated, use %q instead.", kind, newKind)
|
||||||
|
kind = newKind
|
||||||
|
}
|
||||||
if disabledKinds[kind] {
|
if disabledKinds[kind] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if kinds.GetKindAny(kind) == "" {
|
||||||
|
logger.Warnf("Unknown kind %q in outputs configuration.", kind)
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, format := range formats {
|
for _, format := range formats {
|
||||||
if isRssDisabled && format == "rss" {
|
if isRssDisabled && format == "rss" {
|
||||||
// Legacy config.
|
// Legacy config.
|
||||||
|
|
|
@ -1612,12 +1612,41 @@ List.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDisableKindsUnknown(t *testing.T) {
|
func TestKindsUnknown(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
files := `
|
files := `
|
||||||
-- hugo.toml --
|
-- hugo.toml --
|
||||||
disableKinds = ['foo', 'home']
|
disableKinds = ['foo', 'home']
|
||||||
|
[outputs]
|
||||||
|
foo = ['HTML', 'AMP', 'RSS']
|
||||||
|
-- layouts/_default/list.html --
|
||||||
|
List.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
b := NewIntegrationTestBuilder(
|
||||||
|
IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
LogLevel: logg.LevelWarn,
|
||||||
|
},
|
||||||
|
).Init()
|
||||||
|
|
||||||
|
b.AssertLogContains("WARN Unknown kind \"foo\" in disableKinds configuration.\n")
|
||||||
|
b.AssertLogContains("WARN Unknown kind \"foo\" in outputs configuration.\n")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeprecateTaxonomyTerm(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
disableKinds = ['taxonomyTerm']
|
||||||
|
[outputs]
|
||||||
|
taxonomyterm = ['HTML', 'AMP', 'RSS']
|
||||||
-- layouts/_default/list.html --
|
-- layouts/_default/list.html --
|
||||||
List.
|
List.
|
||||||
|
|
||||||
|
@ -1633,8 +1662,7 @@ List.
|
||||||
},
|
},
|
||||||
).Init()
|
).Init()
|
||||||
|
|
||||||
fmt.Println("LOG:", b.LogString())
|
b.AssertLogContains("WARN DEPRECATED: Kind \"taxonomyterm\" used in disableKinds is deprecated, use \"taxonomy\" instead.\n")
|
||||||
|
b.AssertLogContains("WARN DEPRECATED: Kind \"taxonomyterm\" used in outputs configuration is deprecated, use \"taxonomy\" instead.\n")
|
||||||
b.AssertLogContains("WARN Unknown kind \"foo\" in disableKinds\n")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,3 +93,15 @@ func GetKindAny(s string) string {
|
||||||
}
|
}
|
||||||
return kindMapTemporary[strings.ToLower(s)]
|
return kindMapTemporary[strings.ToLower(s)]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsDeprecatedAndReplacedWith returns the new kind if the given kind is deprecated.
|
||||||
|
func IsDeprecatedAndReplacedWith(s string) string {
|
||||||
|
s = strings.ToLower(s)
|
||||||
|
|
||||||
|
switch s {
|
||||||
|
case "taxonomyterm":
|
||||||
|
return KindTaxonomy
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue