summaryrefslogtreecommitdiffstats
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-18 11:21:27 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-26 15:00:44 +0200
commitf9978ed16476ca6d233a89669c62c798cdf9db9d (patch)
tree02edb31008b997a3e77055060a34971fe9e8c5a4 /tpl
parent58d4c0a8be8beefbd7437b17bf7a9a381164d09b (diff)
Image resource refactor
This commit pulls most of the image related logic into its own package, to make it easier to reason about and extend. This is also a rewrite of the transformation logic used in Hugo Pipes, mostly to allow constructs like the one below: {{ ($myimg | fingerprint ).Width }} Fixes #5903 Fixes #6234 Fixes #6266
Diffstat (limited to 'tpl')
-rw-r--r--tpl/resources/resources.go22
1 files changed, 12 insertions, 10 deletions
diff --git a/tpl/resources/resources.go b/tpl/resources/resources.go
index 3d688e21c..e676a3412 100644
--- a/tpl/resources/resources.go
+++ b/tpl/resources/resources.go
@@ -22,7 +22,9 @@ import (
_errors "github.com/pkg/errors"
"github.com/gohugoio/hugo/deps"
+ "github.com/gohugoio/hugo/resources"
"github.com/gohugoio/hugo/resources/resource"
+
"github.com/gohugoio/hugo/resources/resource_factories/bundler"
"github.com/gohugoio/hugo/resources/resource_factories/create"
"github.com/gohugoio/hugo/resources/resource_transformers/integrity"
@@ -174,7 +176,7 @@ func (ns *Namespace) ExecuteAsTemplate(args ...interface{}) (resource.Resource,
}
data := args[1]
- r, ok := args[2].(resource.Resource)
+ r, ok := args[2].(resources.ResourceTransformer)
if !ok {
return nil, fmt.Errorf("type %T not supported in Resource transformations", args[2])
}
@@ -201,9 +203,9 @@ func (ns *Namespace) Fingerprint(args ...interface{}) (resource.Resource, error)
}
}
- r, ok := args[resIdx].(resource.Resource)
+ r, ok := args[resIdx].(resources.ResourceTransformer)
if !ok {
- return nil, fmt.Errorf("%T is not a Resource", args[resIdx])
+ return nil, fmt.Errorf("%T can not be transformed", args[resIdx])
}
return ns.integrityClient.Fingerprint(r, algo)
@@ -211,7 +213,7 @@ func (ns *Namespace) Fingerprint(args ...interface{}) (resource.Resource, error)
// Minify minifies the given Resource using the MediaType to pick the correct
// minifier.
-func (ns *Namespace) Minify(r resource.Resource) (resource.Resource, error) {
+func (ns *Namespace) Minify(r resources.ResourceTransformer) (resource.Resource, error) {
return ns.minifyClient.Minify(r)
}
@@ -219,7 +221,7 @@ func (ns *Namespace) Minify(r resource.Resource) (resource.Resource, error) {
// object or a target path (string) as first argument.
func (ns *Namespace) ToCSS(args ...interface{}) (resource.Resource, error) {
var (
- r resource.Resource
+ r resources.ResourceTransformer
m map[string]interface{}
targetPath string
err error
@@ -266,7 +268,7 @@ func (ns *Namespace) PostCSS(args ...interface{}) (resource.Resource, error) {
}
// We allow string or a map as the first argument in some cases.
-func (ns *Namespace) resolveIfFirstArgIsString(args []interface{}) (resource.Resource, string, bool) {
+func (ns *Namespace) resolveIfFirstArgIsString(args []interface{}) (resources.ResourceTransformer, string, bool) {
if len(args) != 2 {
return nil, "", false
}
@@ -275,26 +277,26 @@ func (ns *Namespace) resolveIfFirstArgIsString(args []interface{}) (resource.Res
if !ok1 {
return nil, "", false
}
- v2, ok2 := args[1].(resource.Resource)
+ v2, ok2 := args[1].(resources.ResourceTransformer)
return v2, v1, ok2
}
// This roundabout way of doing it is needed to get both pipeline behaviour and options as arguments.
-func (ns *Namespace) resolveArgs(args []interface{}) (resource.Resource, map[string]interface{}, error) {
+func (ns *Namespace) resolveArgs(args []interface{}) (resources.ResourceTransformer, map[string]interface{}, error) {
if len(args) == 0 {
return nil, nil, errors.New("no Resource provided in transformation")
}
if len(args) == 1 {
- r, ok := args[0].(resource.Resource)
+ r, ok := args[0].(resources.ResourceTransformer)
if !ok {
return nil, nil, fmt.Errorf("type %T not supported in Resource transformations", args[0])
}
return r, nil, nil
}
- r, ok := args[1].(resource.Resource)
+ r, ok := args[1].(resources.ResourceTransformer)
if !ok {
return nil, nil, fmt.Errorf("type %T not supported in Resource transformations", args[0])
}