config.go (hugo-0.80.0) | : | config.go (hugo-0.81.0) | ||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
// See the License for the specific language governing permissions and | // See the License for the specific language governing permissions and | |||
// limitations under the License. | // limitations under the License. | |||
package minifiers | package minifiers | |||
import ( | import ( | |||
"github.com/gohugoio/hugo/common/maps" | "github.com/gohugoio/hugo/common/maps" | |||
"github.com/gohugoio/hugo/config" | "github.com/gohugoio/hugo/config" | |||
"github.com/gohugoio/hugo/docshelper" | "github.com/gohugoio/hugo/docshelper" | |||
"github.com/gohugoio/hugo/parser" | "github.com/gohugoio/hugo/parser" | |||
"github.com/spf13/cast" | ||||
"github.com/mitchellh/mapstructure" | "github.com/mitchellh/mapstructure" | |||
"github.com/tdewolff/minify/v2/css" | "github.com/tdewolff/minify/v2/css" | |||
"github.com/tdewolff/minify/v2/html" | "github.com/tdewolff/minify/v2/html" | |||
"github.com/tdewolff/minify/v2/js" | "github.com/tdewolff/minify/v2/js" | |||
"github.com/tdewolff/minify/v2/json" | "github.com/tdewolff/minify/v2/json" | |||
"github.com/tdewolff/minify/v2/svg" | "github.com/tdewolff/minify/v2/svg" | |||
"github.com/tdewolff/minify/v2/xml" | "github.com/tdewolff/minify/v2/xml" | |||
) | ) | |||
var defaultTdewolffConfig = tdewolffConfig{ | var defaultTdewolffConfig = tdewolffConfig{ | |||
HTML: html.Minifier{ | HTML: html.Minifier{ | |||
KeepDocumentTags: true, | KeepDocumentTags: true, | |||
KeepConditionalComments: true, | KeepConditionalComments: true, | |||
KeepEndTags: true, | KeepEndTags: true, | |||
KeepDefaultAttrVals: true, | KeepDefaultAttrVals: true, | |||
KeepWhitespace: false, | KeepWhitespace: false, | |||
// KeepQuotes: false, >= v2.6.2 | ||||
}, | }, | |||
CSS: css.Minifier{ | CSS: css.Minifier{ | |||
Decimals: -1, // will be deprecated | Precision: 0, | |||
// Precision: 0, // use Precision with >= v2.7.0 | KeepCSS2: true, | |||
KeepCSS2: true, | ||||
}, | }, | |||
JS: js.Minifier{}, | JS: js.Minifier{}, | |||
JSON: json.Minifier{}, | JSON: json.Minifier{}, | |||
SVG: svg.Minifier{ | SVG: svg.Minifier{ | |||
Decimals: -1, // will be deprecated | Precision: 0, | |||
// Precision: 0, // use Precision with >= v2.7.0 | ||||
}, | }, | |||
XML: xml.Minifier{ | XML: xml.Minifier{ | |||
KeepWhitespace: false, | KeepWhitespace: false, | |||
}, | }, | |||
} | } | |||
type tdewolffConfig struct { | type tdewolffConfig struct { | |||
HTML html.Minifier | HTML html.Minifier | |||
CSS css.Minifier | CSS css.Minifier | |||
JS js.Minifier | JS js.Minifier | |||
skipping to change at line 102 | skipping to change at line 100 | |||
} | } | |||
// Legacy. | // Legacy. | |||
if b, ok := v.(bool); ok { | if b, ok := v.(bool); ok { | |||
conf.MinifyOutput = b | conf.MinifyOutput = b | |||
return | return | |||
} | } | |||
m := maps.ToStringMap(v) | 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) | err = mapstructure.WeakDecode(m, &conf) | |||
if err != nil { | if err != nil { | |||
return | return | |||
} | } | |||
return | return | |||
} | } | |||
func init() { | func init() { | |||
End of changes. 5 change blocks. | ||||
6 lines changed or deleted | 20 lines changed or added |