Comment on sortPosts behaviour

This commit is contained in:
Timur Demin 2021-02-19 16:47:14 +05:00
parent cf65fcc5c3
commit ae794d9d59
No known key found for this signature in database
GPG key ID: 9EDF3F9D9286FA20

View file

@ -43,6 +43,9 @@ func mustParseTmpl(name, value string) *template.Template {
var funcMap template.FuncMap = template.FuncMap{
// sorts posts by date, newest posts go first
"sortPosts": func(posts []*post) []*post {
// sortPosts is most likely to be used in a pipeline, and the
// user has every right to expect it doesn't modify their
// existing posts slice
ps := make(postsSort, len(posts))
copy(ps, posts)
sort.Sort(ps)