-
Notifications
You must be signed in to change notification settings - Fork 752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configurable timestamping for posts #494
base: master
Are you sure you want to change the base?
Conversation
I suggest closing #493 if this PR is accepted. If any changes are requested I would be happy to do so. |
@panr any thoughts? |
OverviewCompletely revamped the system. You can now set any timestamp format in both the site config as well as page frontmatter. If I missed anything, please let me know. Full development timeline can be seen in my website's repository. Took some time and some revisions but this should work fairly well and is fully compatible with any formatting allowed in Hugo according to their docs. You may notice the following snippet before each with chain:
This statement assigns the .Date value as type time to the variable Any formatting set in page front matter takes priority over any value set in the default page config. If a value is not set it defaults to the Full explainer of what's going on:Post dates use the following setup:
The first line, as stated above, sets the The next line Any time you see After the first else statement, we check whether Last updated timestamps use the following format:
The first We then run through the same logic chain as above, but substituting |
@KatieTheDev I like the second approach much more. I also have to check one more thing in the theme regarding the changes, and I'll let you know after the weekend. |
@panr I'm glad to hear. Hope everything works out for you. I'm excited to get this put in! |
Yesterday — while I was testing it — I produced almost exactly the same code as yours, so I guess we are on the same page here ;-) |
Glad to hear! |
@panr Bug discovered! I will be pushing an update to my documentation provided in the example config file. The bug: If you set your server to UTC timezone and the date format has a timezone abbreviation, it may sometimes show the UTC offset rather than the timezone abbreviation. I'm not sure what causes this, but I was able to fix the bug on my server by changing my timezone to my actual timezone. |
@KatieTheDev long time no see, sorry about that. I revisited this PR and found a bug regarding using the localization tokens (eg: Not sure about the fix, but this helped:
It seems that Can you recreate the bug on your setup as well? |
In #493, I discussed potential PR ideas for this feature but I decided to just do it. A demonstration of it working can be found at https://katiethe.dev or my site repo.
I have modified index.html, list.html, and single.html. These files all now have configurable timestamping, not just datestamping.
To enable the new feature, set
showPostTime
to true in hugo.toml. If you want seconds enabled, setpostTimeSeconds
to true. Both are false by default.You can also individually set these params to true in front matter.