b4ae1981d6
This adds generic sort / sortRev functions for use in gmnhg templates which use sort.Sort to sort anything that implements sort.Interface (which includes lists of posts). The existing sortPosts function that used to sort posts in reverse order becomes an alias to sortRev for backwards compatibility.
26 lines
412 B
Go
26 lines
412 B
Go
package gmnhg
|
|
|
|
import gemini "github.com/tdemin/gmnhg"
|
|
|
|
type Post struct {
|
|
Post []byte
|
|
Metadata gemini.HugoMetadata
|
|
Link string
|
|
}
|
|
|
|
// Posts implements sort.Interface.
|
|
type Posts []Post
|
|
|
|
func (p Posts) Len() int {
|
|
return len(p)
|
|
}
|
|
|
|
func (p Posts) Less(i, j int) bool {
|
|
return p[i].Metadata.PostDate.Before(p[j].Metadata.PostDate)
|
|
}
|
|
|
|
func (p Posts) Swap(i, j int) {
|
|
t := p[i]
|
|
p[i] = p[j]
|
|
p[j] = t
|
|
}
|