From 309d61b22064e59f17d3d8cc44b02d9007e24dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 31 Jan 2024 09:43:02 +0100 Subject: [PATCH] output: Prevent setting Name directly in new output formats Name is derived from the map key. Closes #11947 --- hugolib/site_output_test.go | 3 +-- output/config.go | 2 +- output/outputFormat.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go index 9bcb13ea4..a68555574 100644 --- a/hugolib/site_output_test.go +++ b/hugolib/site_output_test.go @@ -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, diff --git a/output/config.go b/output/config.go index a7ebf5107..09d29f184 100644 --- a/output/config.go +++ b/output/config.go @@ -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) diff --git a/output/outputFormat.go b/output/outputFormat.go index 54e7fe98d..981d895b6 100644 --- a/output/outputFormat.go +++ b/output/outputFormat.go @@ -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. // { "identifiers": ["html", "rss"] } - Name string `json:"name"` + Name string `json:"-"` MediaType media.Type `json:"-"`