minifiers: Make keepWhitespace = true default for HTML
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 19 Jul 2021 09:32:47 +0000 (11:32 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 19 Jul 2021 21:35:20 +0000 (23:35 +0200)
Fixes #8771

hugolib/resource_chain_test.go
minifiers/config.go
minifiers/minifiers_test.go
resources/resource_transformers/minifier/minify_test.go

index a367237abef59af4f69149d0174ec0da64d1844b..834fe43570fefa570e17035ffc5a382d36256272 100644 (file)
@@ -456,6 +456,10 @@ func TestResourceChainPostProcess(t *testing.T) {
        rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
 
        b := newTestSitesBuilder(t)
+       b.WithConfigFile("toml", `[minify]
+  [minify.tdewolff]
+    [minify.tdewolff.html]
+      keepWhitespace = false`)
        b.WithContent("page1.md", "---\ntitle: Page1\n---")
        b.WithContent("page2.md", "---\ntitle: Page2\n---")
 
@@ -562,6 +566,11 @@ T6: {{ $bundle1.Permalink }}
                }},
 
                {"minify", func() bool { return true }, func(b *sitesBuilder) {
+                       b.WithConfigFile("toml", `[minify]
+  [minify.tdewolff]
+    [minify.tdewolff.html]
+      keepWhitespace = false
+`)
                        b.WithTemplates("home.html", `
 Min CSS: {{ ( resources.Get "css/styles1.css" | minify ).Content }}
 Min JS: {{ ( resources.Get "js/script1.js" | resources.Minify ).Content | safeJS }}
index 675e5d2b87a901fb92f4d529ec8e23c598d8113f..e56617a06b6d6b1201822c3477dd9d7520c6c6d6 100644 (file)
@@ -35,7 +35,7 @@ var defaultTdewolffConfig = tdewolffConfig{
                KeepConditionalComments: true,
                KeepEndTags:             true,
                KeepDefaultAttrVals:     true,
-               KeepWhitespace:          false,
+               KeepWhitespace:          true,
        },
        CSS: css.Minifier{
                Precision: 0,
index 37e01742053f5d0a6ab78cf57b8ce846959ed1eb..81edba5103e2910a61e6e1b6a11c8a7c8f834cd1 100644 (file)
@@ -23,6 +23,7 @@ import (
        "github.com/gohugoio/hugo/config"
        "github.com/gohugoio/hugo/media"
        "github.com/gohugoio/hugo/output"
+       "github.com/tdewolff/minify/v2/html"
 )
 
 func TestNew(t *testing.T) {
@@ -189,3 +190,31 @@ func TestDecodeConfigDecimalIsNowPrecision(t *testing.T) {
        c.Assert(conf.Tdewolff.CSS.Precision, qt.Equals, 3)
 
 }
+
+// Issue 8771
+func TestDecodeConfigKeepWhitespace(t *testing.T) {
+       c := qt.New(t)
+       v := config.New()
+       v.Set("minify", map[string]interface{}{
+               "tdewolff": map[string]interface{}{
+                       "html": map[string]interface{}{
+                               "keepEndTags": false,
+                       },
+               },
+       })
+
+       conf, err := decodeConfig(v)
+
+       c.Assert(err, qt.IsNil)
+       c.Assert(conf.Tdewolff.HTML, qt.DeepEquals,
+               html.Minifier{
+                       KeepComments:            false,
+                       KeepConditionalComments: true,
+                       KeepDefaultAttrVals:     true,
+                       KeepDocumentTags:        true,
+                       KeepEndTags:             false,
+                       KeepQuotes:              false,
+                       KeepWhitespace:          true},
+       )
+
+}
index b0ebe3171acbc96167b33231adbb780ab6673187..cc5f7af412fd1045cb90d34d03b5bcbd38f992c2 100644 (file)
@@ -38,5 +38,5 @@ func TestTransform(t *testing.T) {
        c.Assert(transformed.RelPermalink(), qt.Equals, "/hugo.min.html")
        content, err := transformed.(resource.ContentProvider).Content()
        c.Assert(err, qt.IsNil)
-       c.Assert(content, qt.Equals, "<h1>Hugo Rocks!</h1>")
+       c.Assert(content, qt.Equals, "<h1> Hugo Rocks! </h1>")
 }