templates/log.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 60 61 62 63 | package templates
import (
"fmt"
"strings"
"alin.ovh/elgit/git"
g "alin.ovh/gomponents"
. "alin.ovh/gomponents/html"
"github.com/go-git/go-git/v5/plumbing"
)
// LogPage renders the commit log page
func LogPage(data PageData, commits []*git.CommitReference) g.Node {
return Page(data, []g.Node{
RepoHeader(data),
RenderNav(data),
Main(
Log(data, commits),
),
})
}
func Log(data PageData, commits []*git.CommitReference) g.Node {
return Div(Class("log"),
g.Map(commits, func(commit *git.CommitReference) g.Node {
return g.Group{
Div(Class("commit-header"),
A(
Href(fmt.Sprintf("/%s/commit/%s", data.Repo.Slug, commit.Hash.String())),
Class("commit-message"),
g.Text(firstLine(commit.Message)),
),
g.Text(" "),
g.If(
commit.HasReference(),
g.Map(commit.References(), func(ref *plumbing.Reference) g.Node {
return A(
Href(fmt.Sprintf("/%s/tree/%s/", data.Repo.Slug, ref.Name().Short())),
Class("commit-reference"),
g.Text(ref.Name().Short()),
)
}),
),
),
Div(
Class("commit-time"),
CommitTime(commit.Author.When),
),
Div(
Class("commit-author"),
CommitAuthor(commit.Author),
),
}
}),
)
}
func firstLine(message string) string {
before, _, _ := strings.Cut(message, "\n")
return before
}
|