all repos — legit @ 1872ca726ab9b0105481ba2404b01e7aeb43bbee

web frontend for git, written in go

routes: description and humanized time to index
Anirudh Oppiliappan x@icyphox.sh
Wed, 14 Dec 2022 17:38:48 +0530
commit

1872ca726ab9b0105481ba2404b01e7aeb43bbee

parent

d879c2dfb088cb7911e322694c101fb0bdf7c0c0

4 files changed, 26 insertions(+), 7 deletions(-)

jump to
M go.modgo.mod

@@ -5,6 +5,7 @@

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 )
M go.sumgo.sum

@@ -21,6 +21,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=

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=
M routes/routes.goroutes/routes.go

@@ -6,9 +6,9 @@ "log"

"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 @@ log.Printf("reading scan path: %s", err)

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 @@ d.Write500(w)

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 @@ t := template.Must(template.ParseGlob(tpath))

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)
M templates/index.htmltemplates/index.html

@@ -12,12 +12,14 @@ <main>

<table> <tr> <td>repository</td> + <td>description</td> <td>last active</td> </tr> - {{ range $repo, $lc := .info }} + {{ range .info }} <tr> - <td><a href="/{{ $repo }}">{{ $repo }}</a></td> - <td>{{ $lc }}</td> + <td><a href="/{{ .Name }}">{{ .Name }}</a></td> + <td>{{ .Desc }}</td> + <td>{{ .Idle }}</td> </tr> {{ end }} </table>