sorting content list on /author page by file modtime: working on issue #1

pull/8/head
Stephen Searles 7 years ago
parent 80e391d317
commit dae9f296fa
  1. 21
      templates.go

@ -7,7 +7,9 @@ import (
"os"
"path"
"path/filepath"
"sort"
"strings"
"time"
"git.stephensearles.com/stephen/acedoc"
@ -15,7 +17,11 @@ import (
)
func (t tmplData) Content() ([]string, error) {
var files []string
type file struct {
name string
modtime time.Time
}
var files = []file{}
err := filepath.Walk(path.Join(t.Site.Root, "content"), func(name string, fi os.FileInfo, err error) error {
if err != nil {
@ -31,16 +37,25 @@ func (t tmplData) Content() ([]string, error) {
return err
}
files = append(files, name)
files = append(files, file{name, fi.ModTime()})
return nil
})
sort.Slice(files, func(i, j int) bool {
return files[i].modtime.Before(files[j].modtime)
})
if err != nil {
fmt.Println(err)
return nil, err
}
return files, nil
var filenames []string
for _, file := range files {
filenames = append(filenames, file.name)
}
return filenames, nil
}
func (t tmplData) ContentTypes() ([]string, error) {

Loading…
Cancel
Save