GitInfo
语法
PAGE.GitInfo
返回
source.GitInfo
Page
对象上的 GitInfo
方法返回一个带有附加方法的对象。
先决条件
安装 Git,创建一个仓库,并提交您的项目文件。
您还必须允许 Hugo 访问您的仓库。在您的站点配置中
hugo。
enableGitInfo: true
enableGitInfo = true
{
"enableGitInfo": true
}
或者,在构建站点时使用命令行标志
hugo --enableGitInfo
方法
AbbreviatedHash
(string
)缩写的提交哈希值。
{{ with .GitInfo }}
{{ .AbbreviatedHash }} → aab9ec0b3
{{ end }}
AuthorDate
(time.Time
)作者日期。
{{ with .GitInfo }}
{{ .AuthorDate.Format "2006-01-02" }} → 2023-10-09
{{ end }}
AuthorEmail
(string
)作者的电子邮件地址,遵循 gitmailmap。
{{ with .GitInfo }}
{{ .AuthorEmail }} → [email protected]
{{ end }}
AuthorName
(string
)作者的姓名,遵循 gitmailmap。
{{ with .GitInfo }}
{{ .AuthorName }} → John Smith
{{ end }}
CommitDate
(time.Time
)提交日期。
{{ with .GitInfo }}
{{ .CommitDate.Format "2006-01-02" }} → 2023-10-09
{{ end }}
Hash
(string
)提交哈希值。
{{ with .GitInfo }}
{{ .Hash }} → aab9ec0b31ebac916a1468c4c9c305f2bebf78d4
{{ end }}
Subject
(string
)提交消息主题。
{{ with .GitInfo }}
{{ .Subject }} → Add tutorials
{{ end }}
Body
(string
)提交消息正文。
{{ with .GitInfo }}
{{ .Body }} → - Two new pages added.
{{ end }}
上次修改日期
默认情况下,当 enableGitInfo
为 true
时,Page
对象上的 Lastmod
方法会返回包含该文件的最后一次提交的 Git AuthorDate。
您可以在站点配置中更改此行为。