Migration This is my new public git source viewer. Source coming soon. Please contact with concerns/bugs. Contact me

internal/modules/meta.go

4bda28df3ab3dbfcc789dcbbb184cabc8cac9398 · 606 B · 27 lines raw

1 package modules
2
3 import (
4 "time"
5
6 "gsg/internal/core"
7 )
8
9 type Meta struct {
10 core.RepoInfo
11 DefaultRef string
12 LastCommit time.Time
13 Commits int
14 }
15
16 func init() { core.Register("meta", metaMod) }
17
18 // meta: repository identity plus freshness. Used by the repo view, the
19 // index view, and the JSON endpoint -- computed once per page thanks to
20 // the Ctx cache.
21 func metaMod(c *core.Ctx, args ...string) (any, error) {
22 m := Meta{RepoInfo: c.Info, DefaultRef: c.Repo.HeadRef()}
23 if log, err := c.Repo.Log(c.Ref, 1, 0, false); err == nil && len(log) > 0 {
24 m.LastCommit = log[0].When
25 }
26 return m, nil
27 }