]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
output: Prevent setting Name directly in new output formats
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 31 Jan 2024 08:43:02 +0000 (09:43 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 31 Jan 2024 08:43:02 +0000 (09:43 +0100)
Name is derived from the map key.

Closes #11947

hugolib/site_output_test.go
output/config.go
output/outputFormat.go

index 9bcb13ea49105c6ac31dda435d23d4a98e858dcd..a68555574c09c2e326f27eee6a599b53ab6ca338 100644 (file)
@@ -330,8 +330,7 @@ func TestGetOutputFormatRel(t *testing.T) {
        b := newTestSitesBuilder(t).
                WithSimpleConfigFileAndSettings(map[string]any{
                        "outputFormats": map[string]any{
-                               "humansTXT": map[string]any{
-                                       "name":        "HUMANS",
+                               "HUMANS": map[string]any{
                                        "mediaType":   "text/plain",
                                        "baseName":    "humans",
                                        "isPlainText": true,
index a7ebf51070a7f0502a9c16352737bae32fe2e522..09d29f1842f8e132fc6f5e3d036e80be1b265d11 100644 (file)
@@ -65,10 +65,10 @@ func DecodeConfig(mediaTypes media.Types, in any) (*config.ConfigNamespace[map[s
                                }
 
                                newOutFormat := defaultOutputFormat
-                               newOutFormat.Name = k
                                if err := decode(mediaTypes, v, &newOutFormat); err != nil {
                                        return f, nil, err
                                }
+                               newOutFormat.Name = k
 
                                f = append(f, newOutFormat)
 
index 54e7fe98d9c2c803cd483606ee1a8b91f81236f5..981d895b6b81aa263ab4bb780b29343bfd78f1fb 100644 (file)
@@ -29,7 +29,7 @@ type Format struct {
        // The Name is used as an identifier. Internal output formats (i.e. html and rss)
        // can be overridden by providing a new definition for those types.
        // <docsmeta>{ "identifiers": ["html", "rss"] }</docsmeta>
-       Name string `json:"name"`
+       Name string `json:"-"`
 
        MediaType media.Type `json:"-"`