sort users by mtime

master
nate smith 2019-09-10 16:25:19 -05:00
parent 623d411b88
commit b43e94c2ed
1 changed files with 8 additions and 1 deletions

View File

@ -21,6 +21,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort"
"strings" "strings"
"time" "time"
) )
@ -235,7 +236,11 @@ func getDefaultHTML() ([]byte, error) {
return defaultIndexHTML, nil return defaultIndexHTML, nil
} }
type usersByMtime []*user type byMtime []*user
func (x byMtime) Len() int { return len(x) }
func (x byMtime) Less(i, j int) bool { return x[i].Mtime > x[j].Mtime } // because we want DESC
func (x byMtime) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
func getUsers() (users []*user, err error) { func getUsers() (users []*user, err error) {
// TODO sort by mtime // TODO sort by mtime
@ -332,6 +337,8 @@ func tdp() (tildeData, error) {
return tildeData{}, fmt.Errorf("could not determine uptime: %s", err) return tildeData{}, fmt.Errorf("could not determine uptime: %s", err)
} }
sort.Sort(byMtime(users))
return tildeData{ return tildeData{
Name: "tilde.town", Name: "tilde.town",
URL: "https://tilde.town", URL: "https://tilde.town",