Open onnimonni opened 11 months ago
We already have CommitDate
and AuthorDate
using these flags:
%ci
committer date, ISO 8601-like format
%ai
author date, ISO 8601-like format
I have looked in the Git docs and found this:
%ad
author date (format respects --date= option)
What is the difference between the two author dates?
Can you point me where the CommitDate
is documented? It's very likely I just wasn't aware of this 🙇
Yea, commitDate was missing from the documentation (I have updated it), but this is the struct we're returning:
// GitInfo provides information about a version controlled 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"`
}
[By looking at all issues, it seems this one matches my question (if not, sorry for adding noise to this discussion ; just tell me and I'll open another one).]
Currently AuthorDate
and CommitDate
are set to the same value: the last commit about the file. It is indeed a really awesome feature: being able to add an update date on our final web page to show when it has been modified. As the original author of this Issue, I would also be interested in the creation date of a committed file (if I understood well, it should be AuthorDate
).
It is then still normal that both dates are set to the same one?
It seems the resolution of this Issue has been postponed to v0.125.0. I assume we have to wait for this version of Hugo to have a clear difference between AuthorDate
and CommitDate
, isn't it?
AuthorDate and CommitDate are set to the same value
They are both related to the last commit, but they represent different things. For example
git log -1 --pretty="format:hash: %H %nsubject: %s %nauthor date: %ai %nauthor name: %an %ncommit date: %ci %ncommitter name: %cn"
hash: 54a8f0ce21015df7f9927dca358b6d09a560e37b
subject: resources: Use different cache key when copying resources
author date: 2024-03-25 14:17:57 -0700
author name: Joe Mooring
commit date: 2024-03-27 09:59:59 +0100
committer name: Bjørn Erik Pedersen
See the Git documentation for details.
The author is the person who originally wrote the work, whereas the committer is the person who last applied the work.
Getting the date that a file was added to the repository (its first commit) is an expensive (slow) operation, so I don't see us adding that capability. You could run an external script to dump the creation dates into a data file (keyed by commit hash), then access the values with site.Data.something
. This SO post describes the basic approach:
But it's really, really slow. For example, it took 56 seconds when I ran it against the content directory of the Hugo documentation repository, a site that builds in < 2 seconds with a primed cache.
Ok. I better understand now. Thank you very much.
Indeed, 56 seconds is very slow. Slowing down a so fast site generation would really be a shame. So, forget about my question/request. And sorry for having spoiled this thread.
Hugo already has the the ability to get modified date from git but could we also get the original creation date from git with the:
This should be possible with git: