From 28147cb040fde3b20a2446c9acf4507cf17de762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 11 May 2026 12:26:13 +0200 Subject: [PATCH] Fall back to hugo.buildDate in hugo.BuildDate() in non-vcs builds Fixes #14862 --- common/hugo/hugo.go | 5 +++++ hugolib/site.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go index 9a76ee3b7..28f8b9393 100644 --- a/common/hugo/hugo.go +++ b/common/hugo/hugo.go @@ -61,6 +61,11 @@ type BuildInfo struct { GoVersion string } +// GetBuildDate returns the build date if set by -ldflags="-X github.com/gohugoio/hugo/common/hugo.buildDate=" +func GetBuildDate() string { + return buildDate +} + // GetBuildInfo returns the build info for the current binary. func GetBuildInfo() *BuildInfo { bi := getBuildInfo() diff --git a/hugolib/site.go b/hugolib/site.go index 678fea7cd..9220423c3 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -532,6 +532,10 @@ func newHugoSites( opts.GoVersion = bi.GoVersion } + if opts.BuildDate == "" { + opts.BuildDate = hugo.GetBuildDate() + } + h.hugoInfo = page.NewHugoInfo(opts) var prototype *deps.Deps