diff options
author | Anirudh Oppiliappan <x@icyphox.sh> | 2022-12-14 17:38:48 +0530 |
---|---|---|
committer | Anirudh Oppiliappan <x@icyphox.sh> | 2022-12-14 17:39:27 +0530 |
commit | 1872ca726ab9b0105481ba2404b01e7aeb43bbee (patch) | |
tree | 6e00958263102f297b1a3ff6c2d6b8cd16de754d /routes | |
parent | d879c2dfb088cb7911e322694c101fb0bdf7c0c0 (diff) | |
download | legit-1872ca726ab9b0105481ba2404b01e7aeb43bbee.tar.gz legit-1872ca726ab9b0105481ba2404b01e7aeb43bbee.tar.bz2 legit-1872ca726ab9b0105481ba2404b01e7aeb43bbee.zip |
routes: description and humanized time to index
Diffstat (limited to 'routes')
-rw-r--r-- | routes/routes.go | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/routes/routes.go b/routes/routes.go index 76983ed..aab28f5 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -6,9 +6,9 @@ import ( "net/http" "os" "path/filepath" - "time" "github.com/alexedwards/flow" + "github.com/dustin/go-humanize" "icyphox.sh/legit/config" "icyphox.sh/legit/git" ) @@ -25,7 +25,9 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) { return } - repoInfo := make(map[string]time.Time) + type info struct{ Name, Desc, Idle string } + + infos := []info{} for _, dir := range dirs { path := filepath.Join(d.c.Repo.ScanPath, dir.Name()) @@ -42,7 +44,19 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) { log.Println(err) } - repoInfo[dir.Name()] = c.Author.When + var desc string + db, err := os.ReadFile(filepath.Join(path, "description")) + if err == nil { + desc = string(db) + } else { + desc = "" + } + + infos = append(infos, info{ + Name: dir.Name(), + Desc: desc, + Idle: humanize.Time(c.Author.When), + }) } tpath := filepath.Join(d.c.Template.Dir, "*") @@ -50,7 +64,7 @@ func (d *deps) Index(w http.ResponseWriter, r *http.Request) { data := make(map[string]interface{}) data["meta"] = d.c.Meta - data["info"] = repoInfo + data["info"] = infos if err := t.ExecuteTemplate(w, "index", data); err != nil { log.Println(err) |