summaryrefslogtreecommitdiffstats
path: root/source/fileInfo.go
diff options
context:
space:
mode:
Diffstat (limited to 'source/fileInfo.go')
-rw-r--r--source/fileInfo.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/source/fileInfo.go b/source/fileInfo.go
index f882eb898..9ce601b5b 100644
--- a/source/fileInfo.go
+++ b/source/fileInfo.go
@@ -18,7 +18,9 @@ import (
"path/filepath"
"strings"
"sync"
+ "time"
+ "github.com/bep/gitmap"
"github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/hugofs/files"
@@ -294,3 +296,31 @@ func (sp *SourceSpec) NewFileInfo(fi hugofs.FileMetaInfo) (*FileInfo, error) {
return f, nil
}
+
+func NewGitInfo(info gitmap.GitInfo) GitInfo {
+ return GitInfo(info)
+}
+
+// GitInfo provides information about a version controled source file.
+type GitInfo struct {
+ // Commit hash.
+ Hash string `json:"hash"`
+ // Abbreviated commit hash.
+ AbbreviatedHash string `json:"abbreviatedHash"`
+ // The commit message's subject/title line.
+ Subject string `json:"subject"`
+ // The author name, respecting .mailmap.
+ AuthorName string `json:"authorName"`
+ // The author email address, respecting .mailmap.
+ AuthorEmail string `json:"authorEmail"`
+ // The author date.
+ AuthorDate time.Time `json:"authorDate"`
+ // The commit date.
+ CommitDate time.Time `json:"commitDate"`
+}
+
+// IsZero returns true if the GitInfo is empty,
+// meaning it will also be falsy in the Go templates.
+func (g GitInfo) IsZero() bool {
+ return g.Hash == ""
+}