summaryrefslogtreecommitdiffstats
path: root/helpers/general.go
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/general.go')
-rw-r--r--helpers/general.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/helpers/general.go b/helpers/general.go
index 699ddeb53..aa1e00d3a 100644
--- a/helpers/general.go
+++ b/helpers/general.go
@@ -23,11 +23,14 @@ import (
"os"
"path/filepath"
"sort"
+ "strconv"
"strings"
"sync"
"unicode"
"unicode/utf8"
+ "github.com/mitchellh/hashstructure"
+
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/common/hugo"
@@ -482,3 +485,20 @@ func PrintFs(fs afero.Fs, path string, w io.Writer) {
return nil
})
}
+
+// 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
+ }
+
+ hash, err := hashstructure.Hash(o, nil)
+ if err != nil {
+ panic(err)
+ }
+ return strconv.FormatUint(hash, 10)
+}