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 | package templates import ( "github.com/dustin/go-humanize" "go.alanpearce.eu/elgit/data" g "go.alanpearce.eu/gomponents" c "go.alanpearce.eu/gomponents/components" . "go.alanpearce.eu/gomponents/html" ) func Index(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.Map, 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(g.Text(humanize.Time(repo.LastCommit))), } } |