zwbetz
November 29, 2018, 4:51pm
1
Steps to reproduce:
hugo new site hugo-commit-hash && cd hugo-commit-hash
echo "Hugo commit hash: {{ .Hugo.CommitHash }}" > layouts/index.html
hugo
cat public/index.html
Output of hugo env
:
Hugo Static Site Generator v0.52/extended darwin/amd64 BuildDate: 2018-11-28T14:58:25Z
GOOS="darwin"
GOARCH="amd64"
GOVERSION="go1.11"
bep
November 29, 2018, 4:59pm
2
There are 2 issues with your approach:
You need a Git repository and a committed source.
You need to enable Git info (default off)
As a “proof” that it’s working: https://gohugo.io/maintenance/
zwbetz
November 29, 2018, 5:49pm
3
Ah, silly mistake by me, thanks for pointing that out
So I’ve updated my test case with your feedback:
hugo new site hugo-commit-hash && cd hugo-commit-hash
Create content/_index.md
as:---
title: Index
---
Create layouts/index.html
as:Hugo commit hash: {{ .Hugo.CommitHash }}
<br><br>
{{ $page := .Page.GetPage "/_index.md" }}
Git info: {{ $page.GitInfo }}
Add below line to config.toml
enableGitInfo = true
git init && git add -A && git commit -m "Initial"
hugo
Inspect public/index.html
(and see that commit hash is still blank)Hugo commit hash:
<br><br>
Git info: {3de9712d0faca4221740e45a00b9253475b953d6 3de9712 Initial MyName MyEmail 2018-11-29 11:35:16 -0600 CST}
Thanks for the link. I see this partial is using .GitInfo
, but I don’t see any occurrence of .Hugo.CommitHash
To me, I would expect .Hugo.CommitHash
to work regardless of the site being in a git repo, or git info being enabled. The same way that .Hugo.Version
and .Hugo.BuildDate
work, since they are retrieved from the binary.
Thoughts?
bep
November 29, 2018, 5:59pm
4
OK, I misread your first post.
Hugo.CommitHash should be set at build time. Not sure why it’s not.