Skip to content

Commit 6560fda

Browse files
committed
source: expose Ancestor in GitInfo
Also updates docs and bumps bep/gitmap to v1.7.0 Closes #5693
1 parent 83cfdd7 commit 6560fda

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

Diff for: docs/content/en/methods/page/GitInfo.md

+16
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ This is configurable. See [details].
123123
{{ end }}
124124
```
125125

126+
###### Ancestor
127+
128+
(`*source.GitInfo`) The file-filtered ancestor commit, if any.
129+
130+
```go-html-template
131+
{{ partial "inline/changelog.html" .GitInfo }} → 2023-10-09: Add tutorials
132+
2025-03-26: Edit GitInfo docs
133+
134+
{{ define "_partials/inline/changelog.html" }}
135+
{{ with . }}
136+
{{ partial "inline/changelog.html" .Ancestor }}
137+
{{ .CommitDate.Format "2006-01-02" }}: {{ .Subject }}<br>
138+
{{ end }}
139+
{{ end }}
140+
```
141+
126142
## Last modified date
127143

128144
By default, when `enableGitInfo` is `true`, the `Lastmod` method on a `Page` object returns the Git AuthorDate of the last commit that included the file.

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/aws/aws-sdk-go-v2/service/cloudfront v1.44.10
99
github.com/bep/clocks v0.5.0
1010
github.com/bep/debounce v1.2.0
11-
github.com/bep/gitmap v1.6.0
11+
github.com/bep/gitmap v1.7.0
1212
github.com/bep/goat v0.5.0
1313
github.com/bep/godartsass/v2 v2.5.0
1414
github.com/bep/golibsass v1.2.0

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ github.com/bep/clocks v0.5.0 h1:hhvKVGLPQWRVsBP/UB7ErrHYIO42gINVbvqxvYTPVps=
125125
github.com/bep/clocks v0.5.0/go.mod h1:SUq3q+OOq41y2lRQqH5fsOoxN8GbxSiT6jvoVVLCVhU=
126126
github.com/bep/debounce v1.2.0 h1:wXds8Kq8qRfwAOpAxHrJDbCXgC5aHSzgQb/0gKsHQqo=
127127
github.com/bep/debounce v1.2.0/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
128-
github.com/bep/gitmap v1.6.0 h1:sDuQMm9HoTL0LtlrfxjbjgAg2wHQd4nkMup2FInYzhA=
129-
github.com/bep/gitmap v1.6.0/go.mod h1:n+3W1f/rot2hynsqEGxGMErPRgT41n9CkGuzPvz9cIw=
128+
github.com/bep/gitmap v1.7.0 h1:jvPnRQv5RG6IDPrwoDiwAhTE/DmdEkOW4poFeUYmjI8=
129+
github.com/bep/gitmap v1.7.0/go.mod h1:n+3W1f/rot2hynsqEGxGMErPRgT41n9CkGuzPvz9cIw=
130130
github.com/bep/goat v0.5.0 h1:S8jLXHCVy/EHIoCY+btKkmcxcXFd34a0Q63/0D4TKeA=
131131
github.com/bep/goat v0.5.0/go.mod h1:Md9x7gRxiWKs85yHlVTvHQw9rg86Bm+Y4SuYE8CTH7c=
132132
github.com/bep/godartsass/v2 v2.5.0 h1:tKRvwVdyjCIr48qgtLa4gHEdtRkPF8H1OeEhJAEv7xg=

Diff for: source/fileInfo.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,23 @@ func NewFileInfo(fi hugofs.FileMetaInfo) *File {
155155
}
156156

157157
func NewGitInfo(info gitmap.GitInfo) GitInfo {
158-
return GitInfo(info)
158+
gi := GitInfo{
159+
Hash: info.Hash,
160+
AbbreviatedHash: info.AbbreviatedHash,
161+
Subject: info.Subject,
162+
AuthorName: info.AuthorName,
163+
AuthorEmail: info.AuthorEmail,
164+
AuthorDate: info.AuthorDate,
165+
CommitDate: info.CommitDate,
166+
Body: info.Body,
167+
}
168+
169+
if info.Ancestor != nil {
170+
anc := NewGitInfo(*info.Ancestor)
171+
gi.Ancestor = &anc
172+
}
173+
174+
return gi
159175
}
160176

161177
// GitInfo provides information about a version controlled source file.
@@ -176,10 +192,12 @@ type GitInfo struct {
176192
CommitDate time.Time `json:"commitDate"`
177193
// The commit message's body.
178194
Body string `json:"body"`
195+
// The file-filtered ancestor commit, if any.
196+
Ancestor *GitInfo `json:"ancestor"`
179197
}
180198

181199
// IsZero returns true if the GitInfo is empty,
182200
// meaning it will also be falsy in the Go templates.
183-
func (g GitInfo) IsZero() bool {
184-
return g.Hash == ""
201+
func (g *GitInfo) IsZero() bool {
202+
return g == nil || g.Hash == ""
185203
}

0 commit comments

Comments
 (0)