tpl/partials: Allow any key type in partialCached

Fixes #6572
This commit is contained in:
Bjørn Erik Pedersen
2019-12-02 21:10:27 +01:00
parent 40a092b068
commit 0efb00c2a8
9 changed files with 160 additions and 55 deletions

View File

@@ -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)
}