]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Deprecate taxonomyTerm
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 28 Jul 2023 10:18:59 +0000 (12:18 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 28 Jul 2023 13:14:24 +0000 (15:14 +0200)
In favour of 'taxonomy'

Closes #11256

common/loggers/logger.go
config/allconfig/allconfig.go
hugolib/config_test.go
resources/kinds/kinds.go

index 640611939960d847b66d7f5cf8de9eafd702e222..1bdab991b11f54dbd30959452c60da47d36acf92 100644 (file)
@@ -173,6 +173,7 @@ type Logger interface {
        WarnCommand(command string) logg.LevelLogger
        Warnf(format string, v ...any)
        Warnln(v ...any)
+       Deprecatef(fail bool, format string, v ...any)
 }
 
 type logAdapter struct {
@@ -297,6 +298,15 @@ func (l *logAdapter) sprint(v ...any) string {
        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 {
        l logg.LevelLogger
 }
index 00453fb6c11ec1410e0c794bea58388dc21ccced..1c1b0b9906e2494ff890a10a846c4f72e7c75250 100644 (file)
@@ -240,12 +240,13 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
        disabledKinds := make(map[string]bool)
        for _, kind := range c.DisableKinds {
                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.
-                       kind = "taxonomy"
+                       kind = newKind
                }
                if kinds.GetKindAny(kind) == "" {
-                       logger.Warnf("Unknown kind %q in disableKinds", kind)
+                       logger.Warnf("Unknown kind %q in disableKinds configuration.", kind)
                        continue
                }
                disabledKinds[kind] = true
@@ -254,9 +255,17 @@ func (c *Config) CompileConfig(logger loggers.Logger) error {
        isRssDisabled := disabledKinds["rss"]
        outputFormats := c.OutputFormats.Config
        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] {
                        continue
                }
+               if kinds.GetKindAny(kind) == "" {
+                       logger.Warnf("Unknown kind %q in outputs configuration.", kind)
+                       continue
+               }
                for _, format := range formats {
                        if isRssDisabled && format == "rss" {
                                // Legacy config.
index 9a1d3bcbf9079112ccc4278e294c9022f767be88..e912ff721ed599743bb23210552868e80d3167f8 100644 (file)
@@ -1612,12 +1612,14 @@ List.
 
 }
 
-func TestDisableKindsUnknown(t *testing.T) {
+func TestKindsUnknown(t *testing.T) {
        t.Parallel()
 
        files := `
 -- hugo.toml --
 disableKinds = ['foo', 'home']
+[outputs]
+foo = ['HTML', 'AMP', 'RSS']
 -- layouts/_default/list.html --
 List.
 
@@ -1629,12 +1631,38 @@ List.
                        T:           t,
                        TxtarString: files,
                        LogLevel:    logg.LevelWarn,
-                       BuildCfg:    BuildCfg{SkipRender: true},
                },
        ).Init()
 
-       fmt.Println("LOG:", b.LogString())
+       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 --
+List.
+
+
+
+`
+       b := NewIntegrationTestBuilder(
+               IntegrationTestConfig{
+                       T:           t,
+                       TxtarString: files,
+                       LogLevel:    logg.LevelWarn,
+                       BuildCfg:    BuildCfg{SkipRender: true},
+               },
+       ).Init()
 
-       b.AssertLogContains("WARN  Unknown kind \"foo\" in disableKinds\n")
+       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")
 
 }
index 7bcdb5ca7a4337127b56a6ca4cb1ab876ea18989..b035cdd297e286b5298e2adcf1712dca35d2bfbe 100644 (file)
@@ -93,3 +93,15 @@ func GetKindAny(s string) string {
        }
        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 ""
+       }
+}