How to get a footer with build time?

#1

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 ?

0 Likes

#2

There’s a PR in the works for that.

0 Likes

#3

Hi. Are you asking for the date/time the build started or the amount of time it took to run the build?

0 Likes

#4
{{ .Now }}

Is available everywhere - and is a Go time.Time set at site generation time.

0 Likes

#5

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.

0 Likes

#6

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.

0 Likes

#7

You can format it as you please:

{{ .Now.Format “Jan 2, 2006 at 3:04pm (MST)” }}

See http://golang.org/pkg/time/#Time.Format

2 Likes

#8

@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.

1 Like

#9

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 }}.

0 Likes

#10

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.

0 Likes

#11

I agree! I thought that only I cared about that :slight_smile:.

0 Likes

#12

@bep OK to submit a PR to fix the template for “lastBuildDate” in internal RSS template to use now as @TotallyInformation noted?

1 Like

#13

Ha! OCD is a terrible curse :nerd_face:

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.

0 Likes

#14

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?

0 Likes