summaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-12-02 21:10:27 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-12-03 00:13:47 +0100
commit0efb00c2a86ec3f52000a643f26f54bb2a9dfbd6 (patch)
tree370d64135277eaa825ead0c25d33e99eb218087e /resources
parent40a092b0687d44ecb53ef1fd53001a6299345780 (diff)
tpl/partials: Allow any key type in partialCached
Fixes #6572
Diffstat (limited to 'resources')
-rw-r--r--resources/image.go6
-rw-r--r--resources/images/filters_test.go10
-rw-r--r--resources/internal/key.go25
-rw-r--r--resources/internal/key_test.go7
4 files changed, 9 insertions, 39 deletions
diff --git a/resources/image.go b/resources/image.go
index cdea8a2a7..076f2ae4d 100644
--- a/resources/image.go
+++ b/resources/image.go
@@ -34,8 +34,6 @@ import (
"github.com/gohugoio/hugo/cache/filecache"
"github.com/gohugoio/hugo/resources/images/exif"
- "github.com/gohugoio/hugo/resources/internal"
-
"github.com/gohugoio/hugo/resources/resource"
_errors "github.com/pkg/errors"
@@ -218,7 +216,7 @@ func (i *imageResource) Filter(filters ...interface{}) (resource.Image, error) {
gfilters = append(gfilters, images.ToFilters(f)...)
}
- conf.Key = internal.HashString(gfilters)
+ conf.Key = helpers.HashString(gfilters)
conf.TargetFormat = i.Format
return i.doWithImageConfig(conf, func(src image.Image) (image.Image, error) {
@@ -362,7 +360,7 @@ func (i *imageResource) getImageMetaCacheTargetPath() string {
}
p1, _ := helpers.FileAndExt(df.file)
h, _ := i.hash()
- idStr := internal.HashString(h, i.size(), imageMetaVersionNumber, cfg)
+ idStr := helpers.HashString(h, i.size(), imageMetaVersionNumber, cfg)
return path.Join(df.dir, fmt.Sprintf("%s_%s.json", p1, idStr))
}
diff --git a/resources/images/filters_test.go b/resources/images/filters_test.go
index 658a9a427..1243e483b 100644
--- a/resources/images/filters_test.go
+++ b/resources/images/filters_test.go
@@ -16,7 +16,7 @@ package images
import (
"testing"
- "github.com/gohugoio/hugo/resources/internal"
+ "github.com/gohugoio/hugo/helpers"
qt "github.com/frankban/quicktest"
)
@@ -26,9 +26,9 @@ func TestFilterHash(t *testing.T) {
f := &Filters{}
- c.Assert(internal.HashString(f.Grayscale()), qt.Equals, internal.HashString(f.Grayscale()))
- c.Assert(internal.HashString(f.Grayscale()), qt.Not(qt.Equals), internal.HashString(f.Invert()))
- c.Assert(internal.HashString(f.Gamma(32)), qt.Not(qt.Equals), internal.HashString(f.Gamma(33)))
- c.Assert(internal.HashString(f.Gamma(32)), qt.Equals, internal.HashString(f.Gamma(32)))
+ c.Assert(helpers.HashString(f.Grayscale()), qt.Equals, helpers.HashString(f.Grayscale()))
+ c.Assert(helpers.HashString(f.Grayscale()), qt.Not(qt.Equals), helpers.HashString(f.Invert()))
+ c.Assert(helpers.HashString(f.Gamma(32)), qt.Not(qt.Equals), helpers.HashString(f.Gamma(33)))
+ c.Assert(helpers.HashString(f.Gamma(32)), qt.Equals, helpers.HashString(f.Gamma(32)))
}
diff --git a/resources/internal/key.go b/resources/internal/key.go
index 17543b0d4..d67d4a7e1 100644
--- a/resources/internal/key.go
+++ b/resources/internal/key.go
@@ -13,11 +13,7 @@
package internal
-import (
- "strconv"
-
- "github.com/mitchellh/hashstructure"
-)
+import "github.com/gohugoio/hugo/helpers"
// ResourceTransformationKey are provided by the different transformation implementations.
// It identifies the transformation (name) and its configuration (elements).
@@ -42,23 +38,6 @@ func (k ResourceTransformationKey) Value() string {
return k.Name
}
- return k.Name + "_" + HashString(k.elements...)
-
-}
-
-// HashString returns a hash from the given elements.
-// It will panic if the hash cannot be calculated.
-func HashString(elements ...interface{}) string {
- var o interface{}
- if len(elements) == 1 {
- o = elements[0]
- } else {
- o = elements
- }
+ return k.Name + "_" + helpers.HashString(k.elements...)
- hash, err := hashstructure.Hash(o, nil)
- if err != nil {
- panic(err)
- }
- return strconv.FormatUint(hash, 10)
}
diff --git a/resources/internal/key_test.go b/resources/internal/key_test.go
index 11a52f2e6..38286333d 100644
--- a/resources/internal/key_test.go
+++ b/resources/internal/key_test.go
@@ -34,10 +34,3 @@ func TestResourceTransformationKey(t *testing.T) {
c := qt.New(t)
c.Assert(key.Value(), qt.Equals, "testing_518996646957295636")
}
-
-func TestHashString(t *testing.T) {
- c := qt.New(t)
-
- c.Assert(HashString("a", "b"), qt.Equals, "2712570657419664240")
- c.Assert(HashString("ab"), qt.Equals, "590647783936702392")
-}