diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-01-31 12:34:28 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-01-31 12:34:28 +0100 |
commit | 51615440bf9a932004bca2b69e5805b1ec48427f (patch) | |
tree | 72ee44aa7b7621ddf0452c41b24d8b754119dec5 | |
parent | bd66d30295e5454bb076d3108a89f6c3ad9bcde8 (diff) |
docs: Make null booleans falsy in the docs helper
-rw-r--r-- | commands/gen.go | 2 | ||||
-rw-r--r-- | docs/data/docs.yaml | 4 | ||||
-rw-r--r-- | parser/lowercase_camel_json.go | 16 |
3 files changed, 18 insertions, 4 deletions
diff --git a/commands/gen.go b/commands/gen.go index 11c32d778..ae87091c4 100644 --- a/commands/gen.go +++ b/commands/gen.go @@ -195,7 +195,7 @@ url: %s configProvider := func() docshelper.DocProvider { conf := hugolib.DefaultConfig() conf.CacheDir = "" // The default value does not make sense in the docs. - defaultConfig := parser.LowerCaseCamelJSONMarshaller{Value: conf} + defaultConfig := parser.NullBoolJSONMarshaller{Wrapped: parser.LowerCaseCamelJSONMarshaller{Value: conf}} return docshelper.DocProvider{"config": defaultConfig} } diff --git a/docs/data/docs.yaml b/docs/data/docs.yaml index d5078309b..ed4d1fb09 100644 --- a/docs/data/docs.yaml +++ b/docs/data/docs.yaml @@ -1076,9 +1076,9 @@ config: wrapStandAloneImageWithinParagraph: true renderHooks: image: - enableDefault: null + enableDefault: false link: - enableDefault: null + enableDefault: false renderer: hardWraps: false unsafe: false diff --git a/parser/lowercase_camel_json.go b/parser/lowercase_camel_json.go index 3dd4c24b0..72715a04b 100644 --- a/parser/lowercase_camel_json.go +++ b/parser/lowercase_camel_json.go @@ -25,9 +25,23 @@ import ( // Regexp definitions var ( - keyMatchRegex = regexp.MustCompile(`\"(\w+)\":`) + keyMatchRegex = regexp.MustCompile(`\"(\w+)\":`) + nullEnableBoolRegex = regexp.MustCompile(`\"(enable\w+)\":null`) ) +type NullBoolJSONMarshaller struct { + Wrapped json.Marshaler +} + +func (c NullBoolJSONMarshaller) MarshalJSON() ([]byte, error) { + b, err := c.Wrapped.MarshalJSON() + if err != nil { + return nil, err + } + i := bytes.Index(b, []byte("enableDefault")) + return nullEnableBoolRegex.ReplaceAll(b, []byte(`"$1": false`)), nil +} + // Code adapted from https://gist.github.com/piersy/b9934790a8892db1a603820c0c23e4a7 type LowerCaseCamelJSONMarshaller struct { Value any |