diff options
author | James Tatum <[email protected]> | 2024-01-11 13:30:42 -0800 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-01-25 19:33:14 +0100 |
commit | 8915343075e1de2d175cbd5de467ab212da5a5b9 (patch) | |
tree | dee15e573dbaecde57f2ded834fcc89b90b5a935 /minifiers | |
parent | a541e3b4d48cac704185a644539d3501ff183b19 (diff) | |
download | hugo-8915343075e1de2d175cbd5de467ab212da5a5b9.tar.gz hugo-8915343075e1de2d175cbd5de467ab212da5a5b9.zip |
deps: Update github.com/tdewolff/minify/v2 v2.20.9 => v2.20.13
KeepConditionalComments was deprecated in the upstream library and replaced with KeepSpecialComments. This new option reflects that both conditional comments and Server Side Include comments can be optionally stripped by the minifier. As with KeepConditionalComments, the minifier is configured not to strip them by default.
Diffstat (limited to 'minifiers')
-rw-r--r-- | minifiers/config.go | 40 | ||||
-rw-r--r-- | minifiers/config_test.go | 42 | ||||
-rw-r--r-- | minifiers/minifiers_test.go | 14 |
3 files changed, 80 insertions, 16 deletions
diff --git a/minifiers/config.go b/minifiers/config.go index 8ebcaa5c9..1ebbd1e05 100644 --- a/minifiers/config.go +++ b/minifiers/config.go @@ -28,11 +28,11 @@ import ( var defaultTdewolffConfig = TdewolffConfig{ HTML: html.Minifier{ - KeepDocumentTags: true, - KeepConditionalComments: true, - KeepEndTags: true, - KeepDefaultAttrVals: true, - KeepWhitespace: false, + KeepDocumentTags: true, + KeepSpecialComments: true, + KeepEndTags: true, + KeepDefaultAttrVals: true, + KeepWhitespace: false, }, CSS: css.Minifier{ Precision: 0, @@ -90,17 +90,39 @@ func DecodeConfig(v any) (conf MinifyConfig, err error) { // Handle upstream renames. if td, found := m["tdewolff"]; found { tdm := maps.ToStringMap(td) + for _, key := range []string{"css", "svg"} { if v, found := tdm[key]; found { vm := maps.ToStringMap(v) - if vv, found := vm["decimal"]; found { - vvi := cast.ToInt(vv) - if vvi > 0 { - vm["precision"] = vvi + ko := "decimal" + kn := "precision" + if vv, found := vm[ko]; found { + if _, found = vm[kn]; !found { + vvi := cast.ToInt(vv) + if vvi > 0 { + vm[kn] = vvi + } } + delete(vm, ko) + } + } + } + + // keepConditionalComments was renamed to keepSpecialComments + if v, found := tdm["html"]; found { + vm := maps.ToStringMap(v) + ko := "keepconditionalcomments" + kn := "keepspecialcomments" + if vv, found := vm[ko]; found { + // Set keepspecialcomments, if not already set + if _, found := vm[kn]; !found { + vm[kn] = cast.ToBool(vv) } + // Remove the old key to prevent deprecation warnings + delete(vm, ko) } } + } err = mapstructure.WeakDecode(m, &conf) diff --git a/minifiers/config_test.go b/minifiers/config_test.go index 7169d3fce..9dc20c655 100644 --- a/minifiers/config_test.go +++ b/minifiers/config_test.go @@ -59,3 +59,45 @@ func TestConfigLegacy(t *testing.T) { conf := testconfig.GetTestConfigs(nil, v).Base.Minify c.Assert(conf.MinifyOutput, qt.Equals, true) } + +func TestConfigNewCommentOptions(t *testing.T) { + c := qt.New(t) + v := config.New() + + // setting the old options should automatically set the new options + v.Set("minify", map[string]any{ + "tdewolff": map[string]any{ + "html": map[string]any{ + "keepConditionalComments": false, + }, + "svg": map[string]any{ + "decimal": "5", + }, + }, + }) + + conf := testconfig.GetTestConfigs(nil, v).Base.Minify + + c.Assert(conf.Tdewolff.HTML.KeepSpecialComments, qt.Equals, false) + c.Assert(conf.Tdewolff.SVG.Precision, qt.Equals, 5) + + // the new values should win, regardless of the contents of the old values + v = config.New() + v.Set("minify", map[string]any{ + "tdewolff": map[string]any{ + "html": map[string]any{ + "keepConditionalComments": false, + "keepSpecialComments": true, + }, + "svg": map[string]any{ + "decimal": "5", + "precision": "10", + }, + }, + }) + + conf = testconfig.GetTestConfigs(nil, v).Base.Minify + + c.Assert(conf.Tdewolff.HTML.KeepSpecialComments, qt.Equals, true) + c.Assert(conf.Tdewolff.SVG.Precision, qt.Equals, 10) +} diff --git a/minifiers/minifiers_test.go b/minifiers/minifiers_test.go index 4d5d9feb5..af1b5d996 100644 --- a/minifiers/minifiers_test.go +++ b/minifiers/minifiers_test.go @@ -203,13 +203,13 @@ func TestDecodeConfigKeepWhitespace(t *testing.T) { c.Assert(conf.Tdewolff.HTML, qt.DeepEquals, html.Minifier{ - KeepComments: false, - KeepConditionalComments: true, - KeepDefaultAttrVals: true, - KeepDocumentTags: true, - KeepEndTags: false, - KeepQuotes: false, - KeepWhitespace: false}, + KeepComments: false, + KeepSpecialComments: true, + KeepDefaultAttrVals: true, + KeepDocumentTags: true, + KeepEndTags: false, + KeepQuotes: false, + KeepWhitespace: false}, ) } |