mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	docs: Make null booleans falsy in the docs helper
This commit is contained in:
		@@ -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}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1076,9 +1076,9 @@ config:
 | 
			
		||||
        wrapStandAloneImageWithinParagraph: true
 | 
			
		||||
      renderHooks:
 | 
			
		||||
        image:
 | 
			
		||||
          enableDefault: null
 | 
			
		||||
          enableDefault: false
 | 
			
		||||
        link:
 | 
			
		||||
          enableDefault: null
 | 
			
		||||
          enableDefault: false
 | 
			
		||||
      renderer:
 | 
			
		||||
        hardWraps: false
 | 
			
		||||
        unsafe: false
 | 
			
		||||
 
 | 
			
		||||
@@ -26,8 +26,22 @@ import (
 | 
			
		||||
// Regexp definitions
 | 
			
		||||
var (
 | 
			
		||||
	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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user