show post changelogs
3 files changed, 58 insertions(+), 7 deletions(-)
M internal/vcs/filelog.go → internal/vcs/filelog.go
@@ -2,12 +2,16 @@ package vcs import ( "net/url" + "regexp" + "strings" "time" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" "gitlab.com/tozd/go/errors" ) + +const hashLength = 7 type Author struct { Name string@@ -15,11 +19,14 @@ Email string } type Commit struct { - Hash string - Message string - Author Author - Date time.Time - Link *url.URL + ShortHash string + Hash string + Message string + Summary string + Description string + Author Author + Date time.Time + Link *url.URL } func (r *Repository) makeCommitURL(hash string) *url.URL {@@ -45,9 +52,13 @@ defer fl.Close() cs := make([]*Commit, 0) err = fl.ForEach(func(c *object.Commit) error { + summary, description, _ := strings.Cut(c.Message, "\n") cs = append(cs, &Commit{ - Hash: c.Hash.String(), - Message: c.Message, + ShortHash: c.Hash.String()[:hashLength], + Hash: c.Hash.String(), + Message: c.Message, + Summary: summary, + Description: cleanupDescription(description), Author: Author{ Name: c.Author.Name, Email: c.Author.Email,@@ -64,3 +75,9 @@ } return cs, nil } + +var rewrap = regexp.MustCompile(`\r?\n(\w)`) + +func cleanupDescription(description string) string { + return strings.TrimSpace(rewrap.ReplaceAllString(description, " $1")) +}
M templates/post.go → templates/post.go
@@ -4,6 +4,7 @@ import ( "time" "go.alanpearce.eu/homestead/internal/content" + "go.alanpearce.eu/homestead/internal/vcs" g "maragu.dev/gomponents" . "maragu.dev/gomponents/html"@@ -34,6 +35,29 @@ Ul(Class("p-categories tags"), g.Map(post.Taxonomies.Tags, func(tag string) g.Node { return Li( tagLink(tag, Class("p-category")), + ) + }), + ), + ), + Details(Class("changelog"), + Summary(g.Text("Changelog")), + Ul( + g.Map(post.Commits, func(commit *vcs.Commit) g.Node { + return Li( + TitleAttr(commit.Description), + postDate(commit.Date, ""), + g.Text(" "), + A( + Href(commit.Link.String()), + g.Text(commit.Summary), + ), + g.Text(" "), + g.If( + len(commit.Description) > 0, + Small( + g.Text(" …"), + ), + ), ) }), ),
M templates/style.css → templates/style.css
@@ -219,3 +219,13 @@ svg.rss-icon { height: 1.5ex; width: 1.5ex; } + +.changelog > summary { + font-size: large; +} + +.changelog > ul { + list-style-type: none; + padding-left: unset; + margin-block-start: 0.5rex; +}