diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-03-20 16:34:53 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-03-20 20:35:57 +0100 |
commit | 7204b354a9f46778f068a4712447d6d4fefbefd8 (patch) | |
tree | a7d58d64fb9266f5c3f28251cb677b245925e728 /minifiers/config.go | |
parent | 574c2959b8d3338764fa1db102a5e0fd6ed322d9 (diff) |
Some minify configuration adjustments
Diffstat (limited to 'minifiers/config.go')
-rw-r--r-- | minifiers/config.go | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/minifiers/config.go b/minifiers/config.go index 20d122e9b..5ee3aa2f9 100644 --- a/minifiers/config.go +++ b/minifiers/config.go @@ -14,6 +14,7 @@ package minifiers import ( + "github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/docshelper" "github.com/gohugoio/hugo/parser" @@ -61,36 +62,43 @@ type tdewolffConfig struct { XML xml.Minifier } -type minifiersConfig struct { - EnableHTML bool - EnableCSS bool - EnableJS bool - EnableJSON bool - EnableSVG bool - EnableXML bool +type minifyConfig struct { + // Whether to minify the published output (the HTML written to /public). + MinifyOutput bool + + DisableHTML bool + DisableCSS bool + DisableJS bool + DisableJSON bool + DisableSVG bool + DisableXML bool Tdewolff tdewolffConfig } -var defaultConfig = minifiersConfig{ - EnableHTML: true, - EnableCSS: true, - EnableJS: true, - EnableJSON: true, - EnableSVG: true, - EnableXML: true, - +var defaultConfig = minifyConfig{ Tdewolff: defaultTdewolffConfig, } -func decodeConfig(cfg config.Provider) (conf minifiersConfig, err error) { +func decodeConfig(cfg config.Provider) (conf minifyConfig, err error) { conf = defaultConfig - m := cfg.GetStringMap("minifiers") - if m == nil { + // May be set by CLI. + conf.MinifyOutput = cfg.GetBool("minifyOutput") + + v := cfg.Get("minify") + if v == nil { + return + } + + // Legacy. + if b, ok := v.(bool); ok { + conf.MinifyOutput = b return } + m := maps.ToStringMap(v) + err = mapstructure.WeakDecode(m, &conf) if err != nil { @@ -101,11 +109,8 @@ func decodeConfig(cfg config.Provider) (conf minifiersConfig, err error) { } func init() { - docsProvider := func() map[string]interface{} { - docs := make(map[string]interface{}) - docs["minifiers"] = parser.LowerCaseCamelJSONMarshaller{Value: defaultConfig} - return docs - + docsProvider := func() docshelper.DocProvider { + return docshelper.DocProvider{"config": map[string]interface{}{"minify": parser.LowerCaseCamelJSONMarshaller{Value: defaultConfig}}} } - docshelper.AddDocProvider("config", docsProvider) + docshelper.AddDocProviderFunc(docsProvider) } |