aboutsummaryrefslogtreecommitdiffstats
path: root/entry.go
diff options
context:
space:
mode:
Diffstat (limited to 'entry.go')
-rw-r--r--entry.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/entry.go b/entry.go
index 189014f..ddb3bd8 100644
--- a/entry.go
+++ b/entry.go
@@ -4,8 +4,8 @@ import (
"os"
"path/filepath"
"regexp"
+ "sort"
"strconv"
- "fmt"
)
/*
@@ -28,7 +28,8 @@ func findEntries(root string) (entries []Renderer) {
baseEntryRegex := regexp.MustCompile("([A-z\\-]+)\\.md")
logEntryRegex := regexp.MustCompile("(20[0-9]{2})-([0-9]{2})-([0-9]{2})-([A-z\\-]+)\\.md")
- fmt.Println(root)
+ logEntries := make([]logEntry, 0)
+
err := filepath.Walk(root, func(p string, f os.FileInfo, e error) error {
if !f.IsDir() && baseEntryRegex.MatchString(f.Name()) {
baseCaptures := baseEntryRegex.FindStringSubmatch(f.Name())
@@ -47,7 +48,7 @@ func findEntries(root string) (entries []Renderer) {
day: d,
month: m,
year: y}
- entries = append(entries, newLogEntry)
+ logEntries = append(logEntries, newLogEntry)
} else {
entries = append(entries, newBaseEntry)
}
@@ -58,5 +59,20 @@ func findEntries(root string) (entries []Renderer) {
panic(err)
}
+ sort.Slice(logEntries, func(i, j int) bool {
+ if logEntries[i].year != logEntries[j].year {
+ return logEntries[i].year > logEntries[j].year
+ } else if logEntries[i].month != logEntries[j].month {
+ return logEntries[i].month > logEntries[j].month
+ } else {
+ return logEntries[i].day > logEntries[j].day
+ }
+ })
+
+ // must append each manually: https://golang.org/doc/faq#convert_slice_of_interface
+ for _, e := range logEntries {
+ entries = append(entries, e)
+ }
+
return
}