diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-02-18 09:32:34 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-02-18 10:19:22 +0100 |
commit | 66beac99c64b5e5fe7bec0bda437ba5858d49a36 (patch) | |
tree | 7bf9bdf40fae21cdd32f2c3a403eddbb99bf33b5 /minifiers | |
parent | 968dd7a711063934af84bd1c017c58a1e66f51bb (diff) | |
download | hugo-66beac99c64b5e5fe7bec0bda437ba5858d49a36.tar.gz hugo-66beac99c64b5e5fe7bec0bda437ba5858d49a36.zip |
deps: Update github.com/tdewolff/minify/v2 v2.6.2 => v2.9.13
Fixes #8258
Diffstat (limited to 'minifiers')
-rw-r--r-- | minifiers/config.go | 26 | ||||
-rw-r--r-- | minifiers/minifiers_test.go | 25 |
2 files changed, 44 insertions, 7 deletions
diff --git a/minifiers/config.go b/minifiers/config.go index 5ee3aa2f9..fc707ce37 100644 --- a/minifiers/config.go +++ b/minifiers/config.go @@ -18,6 +18,7 @@ import ( "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/docshelper" "github.com/gohugoio/hugo/parser" + "github.com/spf13/cast" "github.com/mitchellh/mapstructure" "github.com/tdewolff/minify/v2/css" @@ -35,18 +36,15 @@ var defaultTdewolffConfig = tdewolffConfig{ KeepEndTags: true, KeepDefaultAttrVals: true, KeepWhitespace: false, - // KeepQuotes: false, >= v2.6.2 }, CSS: css.Minifier{ - Decimals: -1, // will be deprecated - // Precision: 0, // use Precision with >= v2.7.0 - KeepCSS2: true, + Precision: 0, + KeepCSS2: true, }, JS: js.Minifier{}, JSON: json.Minifier{}, SVG: svg.Minifier{ - Decimals: -1, // will be deprecated - // Precision: 0, // use Precision with >= v2.7.0 + Precision: 0, }, XML: xml.Minifier{ KeepWhitespace: false, @@ -99,6 +97,22 @@ func decodeConfig(cfg config.Provider) (conf minifyConfig, err error) { m := maps.ToStringMap(v) + // Handle upstream renames. + if td, found := m["tdewolff"]; found { + tdm := cast.ToStringMap(td) + for _, key := range []string{"css", "svg"} { + if v, found := tdm[key]; found { + vm := cast.ToStringMap(v) + if vv, found := vm["decimal"]; found { + vvi := cast.ToInt(vv) + if vvi > 0 { + vm["precision"] = vvi + } + } + } + } + } + err = mapstructure.WeakDecode(m, &conf) if err != nil { diff --git a/minifiers/minifiers_test.go b/minifiers/minifiers_test.go index 9e62c5d50..1a2d56e30 100644 --- a/minifiers/minifiers_test.go +++ b/minifiers/minifiers_test.go @@ -34,7 +34,7 @@ func TestNew(t *testing.T) { var rawJS string var minJS string rawJS = " var foo =1 ; foo ++ ; " - minJS = "var foo=1;foo++;" + minJS = "var foo=1;foo++" var rawJSON string var minJSON string @@ -165,3 +165,26 @@ func TestBugs(t *testing.T) { c.Assert(b.String(), qt.Equals, test.expectedMinString) } } + +// Renamed to Precision in v2.7.0. Check that we support both. +func TestDecodeConfigDecimalIsNowPrecision(t *testing.T) { + c := qt.New(t) + v := viper.New() + v.Set("minify", map[string]interface{}{ + "disablexml": true, + "tdewolff": map[string]interface{}{ + "css": map[string]interface{}{ + "decimal": 3, + }, + "svg": map[string]interface{}{ + "decimal": 3, + }, + }, + }) + + conf, err := decodeConfig(v) + + c.Assert(err, qt.IsNil) + c.Assert(conf.Tdewolff.CSS.Precision, qt.Equals, 3) + +} |