package html import ( "fmt" "github.com/dustin/go-humanize" "go.jolheiser.com/ugit/assets" "go.jolheiser.com/ugit/internal/git" ) type IndexContext struct { BaseContext Profile IndexProfile Repos []*git.Repo } type IndexProfile struct { Username string Email string Links []IndexLink } type IndexLink struct { Name string URL string } func lastCommitTime(repo *git.Repo, human bool) string { c, err := repo.LastCommit() if err != nil { return "" } if human { return humanize.Time(c.When) } return c.When.Format("01/02/2006 03:04:05 PM") } func lastCommit(repo *git.Repo) *git.Commit { c, err := repo.LastCommit() if err != nil { return nil } return &c } templ Index(ic IndexContext) { @base(ic.BaseContext) { { ic.Title } { ic.Description } if ic.Profile.Username != "" { { `@` + ic.Profile.Username } } if ic.Profile.Email != "" { @templ.Raw(string(assets.EmailIcon)) { ic.Profile.Email } } for _, link := range ic.Profile.Links { @templ.Raw(string(assets.LinkIcon)) { link.Name } } for _, repo := range ic.Repos { {{ commit := lastCommit(repo) }} { repo.Name() } { repo.Meta.Description } if commit != nil { { commit.Short() } { ": " + commit.Summary() } } for _, tag := range repo.Meta.Tags.Slice() { { tag } } { lastCommitTime(repo, true) } } } }