routes: sort repo index by last idle
Anirudh Oppiliappan x@icyphox.sh
Sun, 18 Dec 2022 11:19:14 +0530
1 files changed,
11 insertions(+),
1 deletions(-)
jump to
M
routes/routes.go
→
routes/routes.go
@@ -6,6 +6,8 @@ "log"
"net/http" "os" "path/filepath" + "sort" + "time" "github.com/alexedwards/flow" "github.com/dustin/go-humanize"@@ -25,7 +27,10 @@ log.Printf("reading scan path: %s", err)
return } - type info struct{ Name, Desc, Idle string } + type info struct { + Name, Desc, Idle string + d time.Time + } infos := []info{}@@ -51,8 +56,13 @@ infos = append(infos, info{
Name: dir.Name(), Desc: desc, Idle: humanize.Time(c.Author.When), + d: c.Author.When, }) } + + sort.Slice(infos, func(i, j int) bool { + return infos[j].d.Before(infos[i].d) + }) tpath := filepath.Join(d.c.Dirs.Templates, "*") t := template.Must(template.ParseGlob(tpath))