package modules import ( "gsg/internal/core" "gsg/internal/notices" ) func init() { core.Register("notices", noticesMod) } // notices: the site-wide banners followed by the ones for the repository // being viewed, in that order. Site-scoped routes (the index) build a Ctx // with c.Repo == nil and an empty Info.Slug, so this must never touch // c.Repo and must skip the repo half when Slug is empty. A nil default // store (the feature is off) is an empty list, not an error -- the // template uses modOr and guards on Immutable, so an empty list renders // nothing. func noticesMod(c *core.Ctx, args ...string) (any, error) { st := notices.Default() if st == nil { return []notices.Notice(nil), nil } snap := st.Snapshot() out := make([]notices.Notice, 0, len(snap.Doc.Global)+8) out = append(out, snap.Doc.Global...) if c.Info.Slug != "" { out = append(out, snap.Doc.Repos[c.Info.Slug]...) } return out, nil }