mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
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
This commit is contained in:
@@ -29,9 +29,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ metaAssigner = (*genericResource)(nil)
|
||||
_ metaAssigner = (*genericResource)(nil)
|
||||
_ metaAssigner = (*imageResource)(nil)
|
||||
_ metaAssignerProvider = (*resourceAdapter)(nil)
|
||||
)
|
||||
|
||||
type metaAssignerProvider interface {
|
||||
getMetaAssigner() metaAssigner
|
||||
}
|
||||
|
||||
// metaAssigner allows updating metadata in resources that supports it.
|
||||
type metaAssigner interface {
|
||||
setTitle(title string)
|
||||
@@ -50,8 +56,15 @@ func AssignMetadata(metadata []map[string]interface{}, resources ...resource.Res
|
||||
counters := make(map[string]int)
|
||||
|
||||
for _, r := range resources {
|
||||
if _, ok := r.(metaAssigner); !ok {
|
||||
continue
|
||||
var ma metaAssigner
|
||||
mp, ok := r.(metaAssignerProvider)
|
||||
if ok {
|
||||
ma = mp.getMetaAssigner()
|
||||
} else {
|
||||
ma, ok = r.(metaAssigner)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -61,7 +74,6 @@ func AssignMetadata(metadata []map[string]interface{}, resources ...resource.Res
|
||||
resourceSrcKey = strings.ToLower(r.Name())
|
||||
)
|
||||
|
||||
ma := r.(metaAssigner)
|
||||
for _, meta := range metadata {
|
||||
src, found := meta["src"]
|
||||
if !found {
|
||||
|
Reference in New Issue
Block a user