diff options
-rw-r--r-- | entry.go | 22 | ||||
-rw-r--r-- | nav.go | 9 | ||||
-rw-r--r-- | page.go | 2 | ||||
-rw-r--r-- | site.go | 20 |
4 files changed, 39 insertions, 14 deletions
@@ -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 } @@ -1,6 +1,9 @@ package main -import () +import ( + "sort" + "strings" +) type navItem struct { AbsoluteUrl string @@ -12,4 +15,8 @@ func createNavSlice(site *siteData, cfg config) { newNavItem := navItem{AbsoluteUrl: site.baseUrl + "/" + k, Text: v.pageName} site.nav = append(site.nav, newNavItem) } + + sort.Slice(site.nav, func(i, j int) bool { + return strings.Compare(site.nav[i].Text, site.nav[j].Text) < 0 + }) } @@ -1,5 +1,7 @@ package main +import () + /* * This file contains all the code related to turning entries into HTML pages */ @@ -6,13 +6,13 @@ import ( ) type siteData struct { - name string - rawName string - baseUrl string + name string + rawName string + baseUrl string outputPath string - sourcePath string - pages map[string]page - nav []navItem + sourcePath string + pages map[string]page + nav []navItem } func getSites(cfg config) (sites []siteData) { @@ -24,11 +24,11 @@ func getSites(cfg config) (sites []siteData) { for _, f := range files { if f.IsDir() && f.Name() != ".git" { newSite := siteData{ - name: nameify(f.Name()), - rawName: f.Name(), - baseUrl: filepath.Join(cfg.BaseUrl, f.Name()), + name: nameify(f.Name()), + rawName: f.Name(), + baseUrl: filepath.Join(cfg.BaseUrl, f.Name()), outputPath: filepath.Join(cfg.TargetDir, f.Name()), - sourcePath: filepath.Join(cfg.DocsRoot, f.Name())} + sourcePath: filepath.Join(cfg.DocsRoot, f.Name())} sites = append(sites, newSite) } } |