lastmod: git dates commits in the site's timezone #40

Merged
jcoffey-dev merged 1 commits from fix/lastmod-timezone into main 2026-10-19 16:42:42 +00:00
2 changed files with 11 additions and 2 deletions

No files matched your search

+7 -1
View File
@@ -52,7 +52,7 @@ func TestGitLastmod(t *testing.T) {
t.Fatal(err)
}
want := map[string]string{
"a.md": "2026-05-07", // the second commit, in its own zone
"a.md": "2026-05-08", // the second commit, 23:30 at -07:00, in the site's UTC
"docs/b.md": "2026-10-19", // changed, not committed
"new.md": "2026-10-19", // not added yet
"c.md": "2020-01-02", // updated: wins
@@ -69,6 +69,12 @@ func TestGitLastmod(t *testing.T) {
t.Errorf("pages not found: %v", want)
}
// In a site in Arizona, the same commit is the day it was made there.
put("site.yaml", "name: T\nurl: https://example.org\nlastmod: git\ntimezone: America/Phoenix\n")
if s, err = Load(dir, Options{Now: now}); err != nil || s.PageFrom("a.md").Lastmod().Format("2006-01-02") != "2026-05-07" {
t.Errorf("Phoenix: %v %v", err, s.PageFrom("a.md").Lastmod())
}
// Without the setting, or outside git, there are no commit dates.
put("site.yaml", "name: T\nurl: https://example.org\n")
if s, _ = Load(dir, Options{Now: now}); s.PageFrom("a.md").Lastmod().IsZero() == false {
+4 -1
View File
@@ -188,7 +188,10 @@ func Load(dir string, opt Options) (*Site, error) {
today = time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, s.Location)
dates := gitDates(dir, today)
for _, p := range s.Pages {
p.Committed = dates[p.Source]
// In the site's timezone, like today: a commit at 23:30 in
// Arizona is the next day in a UTC site, and an uncommitted
// change built then must get the same date as its commit.
p.Committed = dates[p.Source].In(s.Location)
if _, edited := opt.Overrides[p.Source]; edited {
p.Committed = today // unsaved in the editor: not committed yet
}