I would like hugo to display the build time, when the website was generated, how can I do this currently. Is there a global time.Now variable hugo passes to the templates ?
Thereās a PR in the works for that.
Hi. Are you asking for the date/time the build started or the amount of time it took to run the build?
{{ .Now }}
Is available everywhere - and is a Go time.Time set at site generation time.
Thanks every one, the hugo build time will be useful that pull request looks great.
I was looking for {{ .Now }} which is the time the static website was built. That should be enough for now.
The {{ .Now }} uses goās default time Formatting, which is not very usable. It would be sweet if it sent in a more human readable format or sent all well known formats, which the developer can use in the template.
You can format it as you please:
{{ .Now.Format āJan 2, 2006 at 3:04pm (MST)ā }}
@sheki I misunderstood when I read Build Time for Hugo build time, so @bjornerik nailed it. This may be a little nitpicky, but {{ .Now }}
will return a different time every time you call it. Hugo builds fast enough that it will just be a few milliseconds apart, but it isnāt a constant value throughout the build process, as you can see from the Now()
function.
func (n *Node) Now() time.Time {
return time.Now()
}
As a sidenote, it will also return the time in the timezone the build machine is set to, not UTC.
For anyone else coming across this thread, if you are using version 0.19-DEV or a stable release after 0.18.x, {{ .Now }}
is deprecated. You should use {{ now }}
.
Also noting that the internal RSS template does not seem to use this but rather uses .Date
as the lastBuildDate
which doesnāt seem right to me. Ref.
I agree! I thought that only I cared about that .
@bep OK to submit a PR to fix the template for ālastBuildDateā in internal RSS template to use now
as @TotallyInformation noted?
Ha! OCD is a terrible curse
Iāve realised that I need to amend a number of the internal templates and shortcodes to meet my own requirements. Great to have the starting points though.
I forgot to mention that the existing form has probably messed up a lot of RSS feeds for a long time. I noted in some of my feeds that the date was a long time in the past. Maybe the first page that is accessed?