Closed JeremyMcCormick closed 5 months ago
I might have forgotten to mention that in the page-dates.html
I proposed through #8 , I make the Updated
date visible only if different from the Created
date. Because of some weird coincidence, I sometimes have few minutes difference between both dates though the document has been created/updated in the same time. That's why I compare the two dates with a delta of 5 minutes. If this is not desired here, ignore this delta (as Jeremy did in the example above).
@JeremyMcCormick , in your example, you explicitly use .GitInfo
dates. I have also found useful to use .Date
and .LastMod
as they can have a value depending on which information is available. That is configured in hugo.toml
(or hugo.yaml
).
In my case, I configured they as follows:
enableGitInfo = true
[frontmatter]
date = ['date', 'lastmod', ':fileModTime']
lastmod = ['lastmod', ':git', ':fileModTime', 'date', 'publishDate']
It means the following:
.Date
is set (by priority order) with:
date
given in the FrontMatter (header of the Markdown file)lastmod
given in the FrontMatter.LastMod
is set (still by priority order) with:
lastmod
given in the FrontMatterdate
given in the FrontMatter (probably not necessary)publishDate
given in the FrontMatter (probably not necessary as it is usually used to publish a page in the future)By the way, are you sure about .GitInfo.CommitterDate
? It seems to rather be .GitInfo.CommitDate
(see Hugo GitInfo).
For more readability, I also recommend using this syntax (with
instead of if
), though it is really a personal preference and not a recommandation (using if
and prefixing properties to get with .GitInfo
also works):
{{ with .GitInfo }}
{{ $creationDate = .AuthorDate }}
{{ $updatedDate = .CommitDate }}
{{ end }}
Sorry about the mistake in partials/page-dates.html
. I've just fixed it and committed directly in main
branch.
I also inserted this partial in all single pages. Feel free to remove this line if not desired.
To get the GitInfo through this partial, one should add enableGitInfo = true
in hugo.toml
or add the appropriate option when running Hugo (server or not).
I also noticed that this partial display date and time. In your example, you display only the date. It is probably better as there is no need to deal with any delta. So, feel free to adapte this partial if you prefer to display only the date.
We'll use your partial. I'll close this out.
For instance, this will show the created and updated dates using information from git:
There is a partial
page-dates.html
but this might work better as it is automatic.