| 1 | package slides |
| 2 | |
| 3 | import ( |
| 4 | _ "embed" |
| 5 | "encoding/json" |
| 6 | "net/http" |
| 7 | |
| 8 | "amadan.net/oficina/estilo.git/credits" |
| 9 | "amadan.net/rastrillo/rastrillo" |
| 10 | ) |
| 11 | |
| 12 | //go:embed credits/notices.json |
| 13 | var creditNotices []byte |
| 14 | |
| 15 | type creditInventory struct { |
| 16 | Components []credits.Component `json:"components"` |
| 17 | MissingNotices []string `json:"missing_notices"` |
| 18 | } |
| 19 | |
| 20 | var embeddedCredits = func() creditInventory { |
| 21 | var inventory creditInventory |
| 22 | if err := json.Unmarshal(creditNotices, &inventory); err != nil { |
| 23 | panic(err) |
| 24 | } |
| 25 | return inventory |
| 26 | }() |
| 27 | |
| 28 | type creditsPage struct { |
| 29 | shell |
| 30 | Credits credits.PageData |
| 31 | } |
| 32 | |
| 33 | // credits serves GET /help/open-source, reachable signed out (the |
| 34 | // sign-in page's footer links it) and signed in (the account menu's |
| 35 | // Help). The bar shows whoever is signed in, so the account menu and its |
| 36 | // one Sign out are here too. |
| 37 | // |
| 38 | // Referrer-Policy is strict-origin, not no-referrer (shared chrome spec |
| 39 | // §9.5): the account menu's Sign out chains to id.*/signout, which |
| 40 | // admits the hop by the Referer's origin, and a page that sends no |
| 41 | // referrer at all turns that into id.*'s "Finish signing out" page. |
| 42 | // strict-origin still sends no path or query to anyone, and each credit |
| 43 | // link carries its own no-referrer. |
| 44 | func (a *app) credits(w http.ResponseWriter, r *http.Request) { |
| 45 | title := rastrillo.T(r, "slides.credits.title") |
| 46 | w.Header().Set("Content-Type", "text/html; charset=utf-8") |
| 47 | w.Header().Set("Cache-Control", "no-store") |
| 48 | w.Header().Set("Referrer-Policy", "strict-origin") |
| 49 | render(w, "credits", creditsPage{ |
| 50 | shell: a.publicShell(r, titled(title)), |
| 51 | Credits: credits.PageData{Title: title, MissingNoticeLabel: rastrillo.T(r, "slides.credits.missing"), Components: embeddedCredits.Components}, |
| 52 | }) |
| 53 | } |
| 54 | |
| 55 | func serveCreditsCSS(w http.ResponseWriter, r *http.Request) { |
| 56 | w.Header().Set("Content-Type", "text/css; charset=utf-8") |
| 57 | w.Header().Set("Cache-Control", "no-cache") |
| 58 | w.Write(credits.CSS()) |
| 59 | } |
| 60 | |