spf13/hugo — pull request #570 by mohae (2014-10-19 14:30:49+00:00)
Title: 540: add support for build information output to version command

This resolves issue 540 by adding a formatted date, and optional Git commit hash, to the `version` sub-command output.

If Hugo is compiled normally, e.g. 'go build', the Hugo executable's `mdate` will be used as the `buildDate` for Hugo. Hugo locates its executable, 'hugo', and examines the file's property to obtain this information. This works wherever `hugo` is located and is cross-platform compatible, or should be.

Hugo can also be compiled with some extra flags which provide the compile process with the values to use for the Git commit hash and the buildDate, which will be the time.Now() of the `go build` command execution:

go build -ldflags "-X github.com/spf13/hugo/commands.commitHash `git rev-parse --short HEAD 2>/dev/null` -X github.com/spf13/hugo/commands.buildDate `date +%FT%T`"

This will result in `hugo version` output that looks similar to:

Hugo Static Site Generator v0.13-DEV buildDate: 2014-10-16T09:59:55Z
Hugo Static Site Generator v0.13-DEV-24BBFE7 buildDate: 2014-10-16T10:00:55Z

The format of the date is configurable via the `Params.DateFormat` setting. The `DateFormat` is a string value representing the Go time layout that should be used to format the date output. If `Params.DateFormat` is not set, `time.RFC3339` will be used as the default format.

Configuration setting using `config.yaml` as example:

Params:
DateFormat: "2006-01-02"

Will result in:
Hugo Static Site Generator v0.13-DEV buildDate: 2014-10-16
Hugo Static Site Generator v0.13-DEV-24BBFE7 buildDate: 2014-10-16