Skip to content

Commit

Permalink
docs: Make null booleans falsy in the docs helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jan 31, 2024
1 parent bd66d30 commit 5161544
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion commands/gen.go
Expand Up @@ -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}
}

Expand Down
4 changes: 2 additions & 2 deletions docs/data/docs.yaml
Expand Up @@ -1076,9 +1076,9 @@ config:
wrapStandAloneImageWithinParagraph: true
renderHooks:
image:
enableDefault: null
enableDefault: false
link:
enableDefault: null
enableDefault: false
renderer:
hardWraps: false
unsafe: false
Expand Down
16 changes: 15 additions & 1 deletion parser/lowercase_camel_json.go
Expand Up @@ -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"))

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

i declared and not used

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

i declared and not used (compile)

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

i declared and not used (compile)

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

i declared and not used (compile)

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

i declared and not used (compile)

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

i declared and not used (compile)

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

i declared and not used (compile)

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

i declared and not used (compile)

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

i declared and not used (compile)

Check failure on line 41 in parser/lowercase_camel_json.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

i declared and not used
return nullEnableBoolRegex.ReplaceAll(b, []byte(`"$1": false`)), nil
}

// Code adapted from https://gist.github.com/piersy/b9934790a8892db1a603820c0c23e4a7
type LowerCaseCamelJSONMarshaller struct {
Value any
Expand Down

0 comments on commit 5161544

Please sign in to comment.