lastmod: git dates pages by their last commit #39

Merged
jcoffey-dev merged 1 commits from feature/git-lastmod into main 2026-10-19 16:38:15 +00:00
Owner

New site.yaml setting: lastmod: git.

A page without updated: in its front matter gets the date of the last commit that changed its source file. A page with changes not committed yet, or a file not added yet, gets today's date, so building before a commit gives the date the commit will have. Pages being edited in the editor count as changed.

The sitemap, feeds and .Lastmod use this date. A page's own updated: still wins; otherwise it's the later of the commit and date:.

Safety: git runs read-only, with no optional locks (it never writes the index) and core.fsmonitor off, so a repository's own config can't make it run a program.

Limits: outside a repository, or without git, pages keep their front matter dates. In a shallow clone, a file last changed before the clone's depth has no date.

Checked: gofmt, go vet and go test ./... pass. The new TestGitLastmod builds a real repository with the site in a subfolder and fixed commit dates, and checks commits, uncommitted and new files, updated: winning, no setting, no repository, and a bad value. linuxexpert.net built with it: all 631 pages got the right dates.

**New `site.yaml` setting: `lastmod: git`.** A page without `updated:` in its front matter gets the date of the last commit that changed its source file. A page with changes not committed yet, or a file not added yet, gets today's date, so building before a commit gives the date the commit will have. Pages being edited in the editor count as changed. The sitemap, feeds and `.Lastmod` use this date. A page's own `updated:` still wins; otherwise it's the later of the commit and `date:`. **Safety:** git runs read-only, with no optional locks (it never writes the index) and `core.fsmonitor` off, so a repository's own config can't make it run a program. **Limits:** outside a repository, or without git, pages keep their front matter dates. In a shallow clone, a file last changed before the clone's depth has no date. **Checked:** `gofmt`, `go vet` and `go test ./...` pass. The new TestGitLastmod builds a real repository with the site in a subfolder and fixed commit dates, and checks commits, uncommitted and new files, `updated:` winning, no setting, no repository, and a bad value. linuxexpert.net built with it: all 631 pages got the right dates.
jcoffey-dev added 1 commit 2026-10-19 16:35:36 +00:00
lastmod: git dates pages by their last commit
ci / editor-ui (pull_request) Successful in 1m17s
ci / go (pull_request) Successful in 1m29s
fbc6d220b2
With lastmod: git in site.yaml, a page without updated: in its front
matter gets the date of the last commit that changed its source file,
or today while it has changes not yet committed. The sitemap, feeds and
.Lastmod use it. Git runs read-only: no optional locks and no
file-system monitor. Outside a repository, pages keep their front
matter dates.
jcoffey-dev merged commit b9682852fa into main 2026-10-19 16:38:15 +00:00
jcoffey-dev deleted branch feature/git-lastmod 2026-10-19 16:38:15 +00:00
Sign in to join this conversation.