oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1package docs
2
3// Help → Colophon and Help → Fonts.
4//
5// The Colophon is every open-source project Docs is made with, from
6// estilo's catalog (estilo colophon): what it is, what Docs uses it for,
7// who made it, its licence and where it lives. Nothing in it is written
8// here. colophon.json is what Docs ships, generated from the builds by
9// internal/shipped (`go run ./cmd/docs-colophon`), and
10// TestColophonsMatchWhatShips fails when it is stale. Build turns it into
11// the page at start-up and refuses anything the catalog does not cover.
12//
13// Both pages are public, like every Oficina app's open-source page. A
14// signed-in person gets them from Help with their own chrome; the door does
15// not link them (Paul, 2026-11-19). They need no script and download no font.
16
17import (
18 _ "embed"
19 "encoding/json"
20 "net/http"
21
22 "amadan.net/oficina/estilo.git/colophon"
23 "amadan.net/rastrillo/rastrillo"
24 "github.com/go-chi/chi/v5"
25
26 "github.com/carlosframework/docs/internal/fonts"
27)
28
29//go:embed colophon.json
30var colophonJSON []byte
31
32// builtColophon is Docs' Colophon, built once.
33var builtColophon = func() colophon.Colophon {
34 var shipped struct {
35 Packages []colophon.Package `json:"packages"`
36 }
37 if err := json.Unmarshal(colophonJSON, &shipped); err != nil {
38 panic("docs: colophon.json: " + err.Error())
39 }
40 c, err := colophon.Build("docs", shipped.Packages)
41 if err != nil {
42 panic(err)
43 }
44 return c
45}()
46
47// Colophon is Docs' Colophon: every project the server ships or is built
48// with, by section.
49func Colophon() colophon.Colophon { return builtColophon }
50
51const (
52 colophonPath = "/help/colophon"
53 fontsPath = "/help/fonts"
54)
55
56type colophonPageData struct {
57 Frame Frame
58 Page colophon.Page
59}
60
61type licencePageData struct {
62 Frame Frame
63 Page colophon.LicencePage
64}
65
66func colophonLabels(r *http.Request) colophon.Labels {
67 l := colophon.Labels{
68 Contents: rastrillo.T(r, "docs.colophon.contents"),
69 Sections: map[string]string{},
70 By: rastrillo.T(r, "docs.colophon.by"),
71 Licence: rastrillo.T(r, "docs.colophon.licence"),
72 Version: rastrillo.T(r, "docs.colophon.version"),
73 Home: rastrillo.T(r, "docs.colophon.home"),
74 Source: rastrillo.T(r, "docs.colophon.source"),
75 HomeAndSource: rastrillo.T(r, "docs.colophon.homeandsource"),
76 Back: rastrillo.T(r, "docs.colophon.back"),
77 Missing: rastrillo.T(r, "docs.colophon.missing"),
78 NotIncluded: rastrillo.T(r, "docs.colophon.notincluded"),
79 }
80 for _, id := range []string{"typefaces", "go", "javascript", "rust", "swift", "icons", "data", "tools", "services"} {
81 l.Sections[id] = rastrillo.T(r, "docs.colophon.section."+id)
82 }
83 return l
84}
85
86// helpHeaders are the open-source pages' headers in every Oficina app:
87// no-store, because the bar shows who is signed in, and strict-origin,
88// because the account menu's Sign out chains through id.* by the
89// Referer's origin (shared chrome spec §9.5). Each outside link carries
90// its own no-referrer.
91func helpHeaders(w http.ResponseWriter) {
92 w.Header().Set("Cache-Control", "no-store")
93 w.Header().Set("Referrer-Policy", "strict-origin")
94}
95
96func (h *handlers) colophon(w http.ResponseWriter, r *http.Request) {
97 title := rastrillo.T(r, "docs.colophon.title")
98 data := colophonPageData{
99 Frame: h.frame(r, frameOptions{titleParts: []string{title}}),
100 Page: colophon.Page{
101 Title: title,
102 Intro: []string{rastrillo.T(r, "docs.colophon.intro"), rastrillo.T(r, "docs.colophon.intro.exhaustive")},
103 Labels: colophonLabels(r),
104 LicenceBase: colophonPath + "/",
105 Colophon: builtColophon,
106 },
107 }
108 helpHeaders(w)
109 if err := h.render.page(w, r, "colophon", data); err != nil {
110 h.logger.Error("docs: render colophon", "err", err)
111 h.fail(w, r, http.StatusInternalServerError, failStatus)
112 }
113}
114
115func (h *handlers) colophonLicence(w http.ResponseWriter, r *http.Request) {
116 entry, ok := builtColophon.Entry(chi.URLParam(r, "id"))
117 if !ok {
118 h.fail(w, r, http.StatusNotFound, failRoute)
119 return
120 }
121 title := rastrillo.Tf(r, "docs.colophon.licence.title", "name", entry.Name)
122 data := licencePageData{
123 Frame: h.frame(r, frameOptions{titleParts: []string{title, rastrillo.T(r, "docs.colophon.title")}}),
124 Page: colophon.LicencePage{Title: title, Back: colophonPath + "#colophon-" + entry.ID, Labels: colophonLabels(r), Entry: entry},
125 }
126 helpHeaders(w)
127 if err := h.render.page(w, r, "colophon-licence", data); err != nil {
128 h.logger.Error("docs: render colophon licence", "err", err)
129 h.fail(w, r, http.StatusInternalServerError, failStatus)
130 }
131}
132
133// fontTwin is one font that stands in for one of Word's.
134type fontTwin struct{ Font, Twin string }
135
136type fontsPageData struct {
137 Frame Frame
138 Twins []fontTwin
139 // The page's words, resolved for the request's locale.
140 Title, Word, ColumnFont, ColumnTwin, Default, Export, More, MoreLink string
141 // Colophon is the typefaces section of the Colophon.
142 Colophon string
143}
144
145// helpFonts explains the fonts drawn to the measurements of Word's, from
146// the manifest (fonts.json's twin), so the page names exactly the pairs
147// the font menu has.
148func (h *handlers) helpFonts(w http.ResponseWriter, r *http.Request) {
149 title := rastrillo.T(r, "docs.help.fonts.title")
150 data := fontsPageData{
151 Frame: h.frame(r, frameOptions{titleParts: []string{title}}),
152 Title: title,
153 Word: rastrillo.T(r, "docs.help.fonts.word"),
154 ColumnFont: rastrillo.T(r, "docs.help.fonts.col.font"),
155 ColumnTwin: rastrillo.T(r, "docs.help.fonts.col.twin"),
156 Export: rastrillo.T(r, "docs.help.fonts.export"),
157 More: rastrillo.T(r, "docs.help.fonts.more"),
158 MoreLink: rastrillo.T(r, "docs.help.fonts.colophon"),
159 Colophon: colophonPath + "#colophon-typefaces",
160 }
161 if fonts.Default.Twin != "" {
162 data.Default = rastrillo.Tf(r, "docs.help.fonts.default", "font", fonts.Default.Name, "twin", fonts.Default.Twin)
163 }
164 for _, f := range fonts.Families {
165 if f.Twin != "" {
166 data.Twins = append(data.Twins, fontTwin{Font: f.Name, Twin: f.Twin})
167 }
168 }
169 helpHeaders(w)
170 if err := h.render.page(w, r, "help-fonts", data); err != nil {
171 h.logger.Error("docs: render fonts help", "err", err)
172 h.fail(w, r, http.StatusInternalServerError, failStatus)
173 }
174}
175