aboutsummaryrefslogtreecommitdiffhomepage
path: root/parser
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-01-31 12:34:28 +0100
committerBjørn Erik Pedersen <[email protected]>2024-01-31 12:34:28 +0100
commit51615440bf9a932004bca2b69e5805b1ec48427f (patch)
tree72ee44aa7b7621ddf0452c41b24d8b754119dec5 /parser
parentbd66d30295e5454bb076d3108a89f6c3ad9bcde8 (diff)
downloadhugo-51615440bf9a932004bca2b69e5805b1ec48427f.tar.gz
hugo-51615440bf9a932004bca2b69e5805b1ec48427f.zip
docs: Make null booleans falsy in the docs helper
Diffstat (limited to 'parser')
-rw-r--r--parser/lowercase_camel_json.go16
1 files changed, 15 insertions, 1 deletions
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