]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
docs: Make null booleans falsy in the docs helper
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 31 Jan 2024 11:34:28 +0000 (12:34 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 31 Jan 2024 11:34:28 +0000 (12:34 +0100)
commands/gen.go
docs/data/docs.yaml
parser/lowercase_camel_json.go

index 11c32d7781d0547b08002ca560e3c6b138fa8da1..ae87091c4dc0cd62e08a1ec74cbf3d6030a7cde9 100644 (file)
@@ -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}
                                }
 
index d5078309b96ad120c0deca8d5bedaa1404da5a38..ed4d1fb0986cf7a2e7589fe774b477b78bf16026 100644 (file)
@@ -1076,9 +1076,9 @@ config:
         wrapStandAloneImageWithinParagraph: true
       renderHooks:
         image:
-          enableDefault: null
+          enableDefault: false
         link:
-          enableDefault: null
+          enableDefault: false
       renderer:
         hardWraps: false
         unsafe: false
index 3dd4c24b0916e24e3a4092925832650099648150..72715a04baaf295c212efcf1f90a75e63d6caa2e 100644 (file)
@@ -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