all repos — elgit @ fed19ae329323cca0f7b49624486966fbce8096b

fork of legit: web frontend for git, written in go

use gitweb/gitolite directory layout (including subdirs)

Alan Pearce
commit

fed19ae329323cca0f7b49624486966fbce8096b

parent

9c336ff148d48d09a4f4866798511cdcce50202a

1 file changed, 65 insertions(+), 0 deletions(-)

changed files
A data/entries.go
@@ -0,0 +1,65 @@
+package data + +import ( + "sort" + "time" +) + +type Repository struct { + Name string + Category string + Path string + Slug string + Description string + LastCommit time.Time +} + +type Entry struct { + Name string + LastCommit time.Time + Repositories []*Repository +} + +type Entries struct { + Children []*Entry + Map map[string]*Entry +} + +func (ent *Entries) Add(r Repository) { + if r.Category == "" { + ent.Children = append(ent.Children, &Entry{ + Name: r.Name, + LastCommit: r.LastCommit, + Repositories: []*Repository{&r}, + }) + return + } + t, ok := ent.Map[r.Category] + if !ok { + t := &Entry{ + Name: r.Category, + LastCommit: r.LastCommit, + Repositories: []*Repository{&r}, + } + ent.Map[r.Category] = t + return + } + + if t.LastCommit.IsZero() || t.LastCommit.Before(r.LastCommit) { + t.LastCommit = r.LastCommit + } + + t.Repositories = append(t.Repositories, &r) +} + +func (ent *Entries) Sort() { + sort.Slice(ent.Children, func(i, j int) bool { + return ent.Children[i].LastCommit.After(ent.Children[j].LastCommit) + }) + + for _, entries := range ent.Map { + sort.Slice(entries.Repositories, func(i, j int) bool { + return entries.Repositories[i].LastCommit.After(entries.Repositories[j].LastCommit) + }) + } +}