change post changelog link to point to file's diff
2 files changed, 13 insertions(+), 2 deletions(-)
changed files
M internal/vcs/filelog.go → internal/vcs/filelog.go
@@ -19,6 +19,7 @@ Email string } type Commit struct { + repo *Repository ShortHash string Hash string Message string@@ -54,6 +55,7 @@ cs := make([]*Commit, 0) err = fl.ForEach(func(c *object.Commit) error { summary, description, _ := strings.Cut(c.Message, "\n") cs = append(cs, &Commit{ + repo: r, ShortHash: c.Hash.String()[:hashLength], Hash: c.Hash.String(), Message: c.Message,@@ -81,3 +83,12 @@ func cleanupDescription(description string) string { return strings.TrimSpace(rewrap.ReplaceAllString(description, " $1")) } + +func (c *Commit) MakeFileLink(filename string) *url.URL { + u := c.repo.remoteURL.JoinPath("commit").JoinPath(filename) + q := u.Query() + q.Add("id", c.Hash) + u.RawQuery = q.Encode() + + return u +}
M templates/post.go → templates/post.go
@@ -48,7 +48,7 @@ TitleAttr(commit.Description), postDate(commit.Date, ""), g.Text(" "), A( - Href(commit.Link.String()), + Href(commit.MakeFileLink(post.Input).String()), g.Text(commit.Summary), ), g.Text(" "),@@ -79,7 +79,7 @@ return Span( Class("date last-updated"), g.Text("Last updated: "), A( - Href(post.Commits[0].Link.String()), + Href(post.Commits[0].MakeFileLink(post.Input).String()), postDate(post.Commits[0].Date, "dt-updated"), ), )