diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-12-02 21:10:27 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-12-03 00:13:47 +0100 |
commit | 0efb00c2a86ec3f52000a643f26f54bb2a9dfbd6 (patch) | |
tree | 370d64135277eaa825ead0c25d33e99eb218087e /helpers/general.go | |
parent | 40a092b0687d44ecb53ef1fd53001a6299345780 (diff) |
tpl/partials: Allow any key type in partialCached
Fixes #6572
Diffstat (limited to 'helpers/general.go')
-rw-r--r-- | helpers/general.go | 20 |
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) +} |