Add minify config

Fixes #6750
Updates #6892
This commit is contained in:
SatowTakeshi
2020-02-29 18:44:05 +09:00
committed by Bjørn Erik Pedersen
parent 99958f90fe
commit 574c2959b8
12 changed files with 346 additions and 47 deletions

View File

@@ -18,6 +18,7 @@ import (
"io"
"sync/atomic"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/media"
"github.com/gohugoio/hugo/minifiers"
@@ -73,13 +74,17 @@ type DestinationPublisher struct {
}
// NewDestinationPublisher creates a new DestinationPublisher.
func NewDestinationPublisher(fs afero.Fs, outputFormats output.Formats, mediaTypes media.Types, minify bool) DestinationPublisher {
pub := DestinationPublisher{fs: fs}
func NewDestinationPublisher(fs afero.Fs, outputFormats output.Formats, mediaTypes media.Types, cfg config.Provider) (pub DestinationPublisher, err error) {
pub = DestinationPublisher{fs: fs}
minify := cfg.GetBool("minify")
if minify {
pub.min = minifiers.New(mediaTypes, outputFormats)
pub.min, err = minifiers.New(mediaTypes, outputFormats, cfg)
if err != nil {
return
}
pub.minify = true
}
return pub
return
}
// Publish applies any relevant transformations and writes the file