You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add partial with created and updated dates to page template #9
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).
the date given in the FrontMatter (header of the Markdown file)
the lastmod given in the FrontMatter
the filesystem last modification date
.LastMod is set (still by priority order) with:
the lastmod given in the FrontMatter
the date of the last Git commit that included this file
the filesystem last modification date
the date given in the FrontMatter (probably not necessary)
the 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.
Activity
gmantele commentedon Mar 21, 2024
I might have forgotten to mention that in the
page-dates.htmlI proposed through #8 , I make theUpdateddate visible only if different from theCreateddate. 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).gmantele commentedon Mar 21, 2024
@JeremyMcCormick , in your example, you explicitly use
.GitInfodates. I have also found useful to use.Dateand.LastModas they can have a value depending on which information is available. That is configured inhugo.toml(orhugo.yaml).In my case, I configured they as follows:
It means the following:
.Dateis set (by priority order) with:dategiven in the FrontMatter (header of the Markdown file)lastmodgiven in the FrontMatter.LastModis set (still by priority order) with:lastmodgiven in the FrontMatterdategiven in the FrontMatter (probably not necessary)publishDategiven 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 (
withinstead ofif), though it is really a personal preference and not a recommandation (usingifand prefixing properties to get with.GitInfoalso works):gmantele commentedon Mar 21, 2024
Sorry about the mistake in
partials/page-dates.html. I've just fixed it and committed directly inmainbranch.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 = trueinhugo.tomlor 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.
JeremyMcCormick commentedon Mar 21, 2024
We'll use your partial. I'll close this out.