Replies: 1 comment
-
Nice one — thanks for sharing! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is not really directly related to Doks, but on the websites I've created it sometimes says things like "XX Years a household name in" or on my portfolio it for example mentions my current age. However, this is something that you might forget to update, so why not use the power of Hugo to automatically calculate the number of years since a certain date? I've messed around with different approaches and finally settled on the native "addDate" function which works quite well so I thought why not share my shortcode? (A little contribution to this great theme/website! However feel free to remove this if unwanted)
How to:
You can enter a default date in the shortcode (age.html) so that you can just refer to
{{< age >}}
in your markdown or enter a parameter for a custom calculation like this:{{< age "2022-06-20" >}}
(Year, Month, Day).Installation:
Simply create a new file called "age.html" in your shortcode folder.
Remarks:
There is no rounding. So 1 year and 11 months will return 1.
Beta Was this translation helpful? Give feedback.
All reactions