From 241b21b0fd34d91fccb2ce69874110dceae6f926 Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Wed, 4 Jan 2023 18:24:36 +0100 Subject: Create a struct with all of Hugo's config options Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620 --- minifiers/minifiers.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'minifiers/minifiers.go') diff --git a/minifiers/minifiers.go b/minifiers/minifiers.go index 5a5cec121..2696e1c52 100644 --- a/minifiers/minifiers.go +++ b/minifiers/minifiers.go @@ -39,7 +39,7 @@ type Client struct { // Transformer returns a func that can be used in the transformer publishing chain. // TODO(bep) minify config etc func (m Client) Transformer(mediatype media.Type) transform.Transformer { - _, params, min := m.m.Match(mediatype.Type()) + _, params, min := m.m.Match(mediatype.Type) if min == nil { // No minifier for this MIME type return nil @@ -54,7 +54,7 @@ func (m Client) Transformer(mediatype media.Type) transform.Transformer { // Minify tries to minify the src into dst given a MIME type. func (m Client) Minify(mediatype media.Type, dst io.Writer, src io.Reader) error { - return m.m.Minify(mediatype.Type(), dst, src) + return m.m.Minify(mediatype.Type, dst, src) } // noopMinifier implements minify.Minifier [1], but doesn't minify content. This means @@ -74,13 +74,9 @@ func (m noopMinifier) Minify(_ *minify.M, w io.Writer, r io.Reader, _ map[string // New creates a new Client with the provided MIME types as the mapping foundation. // The HTML minifier is also registered for additional HTML types (AMP etc.) in the // provided list of output formats. -func New(mediaTypes media.Types, outputFormats output.Formats, cfg config.Provider) (Client, error) { - conf, err := decodeConfig(cfg) - +func New(mediaTypes media.Types, outputFormats output.Formats, cfg config.AllProvider) (Client, error) { + conf := cfg.GetConfigSection("minify").(MinifyConfig) m := minify.New() - if err != nil { - return Client{}, err - } // We use the Type definition of the media types defined in the site if found. addMinifier(m, mediaTypes, "css", getMinifier(conf, "css")) @@ -99,7 +95,7 @@ func New(mediaTypes media.Types, outputFormats output.Formats, cfg config.Provid addMinifier(m, mediaTypes, "html", getMinifier(conf, "html")) for _, of := range outputFormats { if of.IsHTML { - m.Add(of.MediaType.Type(), getMinifier(conf, "html")) + m.Add(of.MediaType.Type, getMinifier(conf, "html")) } } @@ -108,7 +104,7 @@ func New(mediaTypes media.Types, outputFormats output.Formats, cfg config.Provid // getMinifier returns the appropriate minify.MinifierFunc for the MIME // type suffix s, given the config c. -func getMinifier(c minifyConfig, s string) minify.Minifier { +func getMinifier(c MinifyConfig, s string) minify.Minifier { switch { case s == "css" && !c.DisableCSS: return &c.Tdewolff.CSS @@ -130,6 +126,6 @@ func getMinifier(c minifyConfig, s string) minify.Minifier { func addMinifier(m *minify.M, mt media.Types, suffix string, min minify.Minifier) { types := mt.BySuffix(suffix) for _, t := range types { - m.Add(t.Type(), min) + m.Add(t.Type, min) } } -- cgit v1.2.3