diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-01-04 18:24:36 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-05-16 18:01:29 +0200 |
commit | 241b21b0fd34d91fccb2ce69874110dceae6f926 (patch) | |
tree | d4e0118eac7e9c42f065815447a70805f8d6ad3e /minifiers/minifiers.go | |
parent | 6aededf6b42011c3039f5f66487a89a8dd65e0e7 (diff) | |
download | hugo-241b21b0fd34d91fccb2ce69874110dceae6f926.tar.gz hugo-241b21b0fd34d91fccb2ce69874110dceae6f926.zip |
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
Diffstat (limited to 'minifiers/minifiers.go')
-rw-r--r-- | minifiers/minifiers.go | 18 |
1 files changed, 7 insertions, 11 deletions
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) } } |