aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2016-12-14 08:56:15 -0800
committerChristine Dodrill <me@christine.website>2016-12-14 08:56:15 -0800
commit305db738ea631140da557fd03d88749cb182fe39 (patch)
tree7fd53792542f6ed4e9a7e8530726e6025193bd1b
parent07fa595e3eb3d9f01af96986fb50a0e61ceecbb6 (diff)
downloadxesite-305db738ea631140da557fd03d88749cb182fe39.tar.xz
xesite-305db738ea631140da557fd03d88749cb182fe39.zip
backend: sort blogposts in the index
-rw-r--r--backend/christine.website/main.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/backend/christine.website/main.go b/backend/christine.website/main.go
index aafdfa3..08a46da 100644
--- a/backend/christine.website/main.go
+++ b/backend/christine.website/main.go
@@ -8,7 +8,9 @@ import (
"os"
"path"
"path/filepath"
+ "sort"
"strings"
+ "time"
"github.com/gernest/front"
)
@@ -20,7 +22,18 @@ type Post struct {
Date string `json:"date"`
}
-var posts []*Post
+type Posts []*Post
+
+func (p Posts) Len() int { return len(p) }
+func (p Posts) Less(i, j int) bool {
+ iDate, _ := time.Parse("2006-01-02", p[i].Date)
+ jDate, _ := time.Parse("2006-01-02", p[j].Date)
+
+ return iDate.Unix() < jDate.Unix()
+}
+func (p Posts) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
+
+var posts Posts
func init() {
err := filepath.Walk("./blog/", func(path string, info os.FileInfo, err error) error {
@@ -59,6 +72,8 @@ func init() {
if err != nil {
panic(err)
}
+
+ sort.Sort(posts)
}
func main() {