routes: description and humanized time to index

This commit is contained in:
Anirudh Oppiliappan 2022-12-14 17:38:48 +05:30
parent d879c2dfb0
commit 1872ca726a
No known key found for this signature in database
GPG key ID: 8A93F96F78C5D4C4
4 changed files with 26 additions and 7 deletions

1
go.mod
View file

@ -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
)

2
go.sum
View file

@ -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=

View file

@ -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)

View file

@ -12,12 +12,14 @@
<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>