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

internal/modules/notices.go

main · 931 B · 29 lines raw

1 package modules
2
3 import (
4 "gsg/internal/core"
5 "gsg/internal/notices"
6 )
7
8 func init() { core.Register("notices", noticesMod) }
9
10 // notices: the site-wide banners followed by the ones for the repository
11 // being viewed, in that order. Site-scoped routes (the index) build a Ctx
12 // with c.Repo == nil and an empty Info.Slug, so this must never touch
13 // c.Repo and must skip the repo half when Slug is empty. A nil default
14 // store (the feature is off) is an empty list, not an error -- the
15 // template uses modOr and guards on Immutable, so an empty list renders
16 // nothing.
17 func noticesMod(c *core.Ctx, args ...string) (any, error) {
18 st := notices.Default()
19 if st == nil {
20 return []notices.Notice(nil), nil
21 }
22 snap := st.Snapshot()
23 out := make([]notices.Notice, 0, len(snap.Doc.Global)+8)
24 out = append(out, snap.Doc.Global...)
25 if c.Info.Slug != "" {
26 out = append(out, snap.Doc.Repos[c.Info.Slug]...)
27 }
28 return out, nil
29 }