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

@@ -29,8 +29,12 @@ type Client struct {
// New creates a new Client given a specification. Note that it is the media types
// configured for the site that is used to match files to the correct minifier.
func New(rs *resources.Spec) *Client {
return &Client{rs: rs, m: minifiers.New(rs.MediaTypes, rs.OutputFormats)}
func New(rs *resources.Spec) (*Client, error) {
m, err := minifiers.New(rs.MediaTypes, rs.OutputFormats, rs.Cfg)
if err != nil {
return nil, err
}
return &Client{rs: rs, m: m}, nil
}
type minifyTransformation struct {
@@ -43,9 +47,7 @@ func (t *minifyTransformation) Key() internal.ResourceTransformationKey {
}
func (t *minifyTransformation) Transform(ctx *resources.ResourceTransformationCtx) error {
if err := t.m.Minify(ctx.InMediaType, ctx.To, ctx.From); err != nil {
return err
}
_ = t.m.Minify(ctx.InMediaType, ctx.To, ctx.From)
ctx.AddOutPathIdentifier(".min")
return nil
}