From 1872ca726ab9b0105481ba2404b01e7aeb43bbee Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Wed, 14 Dec 2022 17:38:48 +0530 Subject: [PATCH] routes: description and humanized time to index --- go.mod | 1 + go.sum | 2 ++ routes/routes.go | 22 ++++++++++++++++++---- templates/index.html | 8 +++++--- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index bce70db..17129aa 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.19 require ( github.com/alexedwards/flow v0.0.0-20220806114457-cf11be9e0e03 github.com/bluekeyes/go-gitdiff v0.7.0 + github.com/dustin/go-humanize v1.0.0 github.com/go-git/go-git/v5 v5.5.1 gopkg.in/yaml.v3 v3.0.0 ) diff --git a/go.sum b/go.sum index 53e07e9..719bc54 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= 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) diff --git a/templates/index.html b/templates/index.html index 91f18b7..3ab82c7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,12 +12,14 @@ + - {{ range $repo, $lc := .info }} + {{ range .info }} - - + + + {{ end }}
repositorydescription last active
{{ $repo }}{{ $lc }}{{ .Name }}{{ .Desc }}{{ .Idle }}