templates/index.go (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | package templates
import (
"time"
"alin.ovh/elgit/data"
g "alin.ovh/gomponents"
c "alin.ovh/gomponents/components"
. "alin.ovh/gomponents/html"
"github.com/dustin/go-humanize"
)
func IndexPage(pd PageData, entries *data.Entries) g.Node {
return Page(pd, g.Group{
Header(
H1(g.Text(pd.Meta.Title)),
H2(g.Text(pd.Meta.Description)),
),
Main(
Div(Class("index"),
g.Map(entries.Children, func(entry *data.Entry) g.Node {
return g.If(len(entry.Repositories) == 1,
Repository(entry.Repositories[0], 0),
)
}),
g.MapMap(entries.Categories, func(category string, entry *data.Entry) g.Node {
return g.Group{
Div(Class("index-category"),
Header(g.Text(category)),
),
g.Map(entry.Repositories, func(repo *data.Repository) g.Node {
return Repository(repo, 1)
}),
}
}),
),
),
})
}
func Repository(repo *data.Repository, level int) g.Node {
return g.Group{
Div(
c.Classes{
"index-name": level == 0,
"index-category-name": level >= 1,
},
A(Href("/"+repo.Slug), g.Text(repo.Name)),
),
Div(Class("desc"), g.Text(repo.Description)),
Div(
Time(
DateTime(repo.LastCommit.Format(time.RFC3339)),
TitleAttr(repo.LastCommit.Format(time.RFC3339)),
g.Text(humanize.Time(repo.LastCommit)),
),
),
}
}
|