oficina / estilo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package theme
2
3import (
4 "embed"
5 "net/http"
6 "strings"
7)
8
9// The chrome is set in the system UI face (estilo.css, --rst-font) and
10// downloads no font: Paul, 2026-10-25, AGENTS.md row 9. This file only
11// keeps v1's two files answering, byte for byte, so a page or cached
12// stylesheet that still names them never meets a 404. No page links them
13// any more and --rst-font names no "Onest", so a page that still does
14// declares a face nothing uses: the font is never downloaded, nothing
15// waits for it and nothing swaps.
16//
17// Onest itself is SIL Open Font License 1.1; an app that still mounts
18// FontHandler serves the file, so it lists credits.Onest() until it
19// stops. Provenance and the licence are in credits/notices/onest-*.
20
21//go:embed fonts/onest-latin.woff2
22var fontFS embed.FS
23
24// FontPrefix is the path FontHandler answers under: v1, frozen. Its
25// bytes never change (TestFontV1IsUnchanged); a stylesheet with a
26// different rule would need a new version, and there is no chrome font
27// to need one.
28//
29// Deprecated: link nothing under it from a new page. Mount FontHandler
30// here only so old pages keep their stylesheet.
31const FontPrefix = "/static/estilo/fonts/v1/"
32
33// fontCSS is v1's stylesheet as it shipped. It said font-display: swap,
34// the flash this branch ends; it is unchanged because it is cached for a
35// year as immutable under this name.
36const fontCSS = `/* Onest, Calma's typeface (estilo theme/fonts.go). */
37@font-face {
38 font-family: "Onest";
39 font-style: normal;
40 font-weight: 300 800;
41 font-display: swap;
42 src: url("` + FontPrefix + `onest-latin.woff2") format("woff2");
43 unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
44}
45`
46
47// FontCSS is v1's stylesheet, served by FontHandler as FontPrefix +
48// "fonts.css".
49//
50// Deprecated: kept for old pages; link nothing to it.
51func FontCSS() []byte { return []byte(fontCSS) }
52
53// FontHandler serves GET and HEAD for FontPrefix + "fonts.css" and
54// FontPrefix + "onest-latin.woff2", v1's bytes. Mount it at FontPrefix;
55// anything else under it is 404. Public, sessionless, and the bytes never
56// change under a name, so both are cached for a year. Keep it mounted
57// while anything might still name v1 (a stale tab, a mockup that hotlinks
58// it); it costs nothing on a page that doesn't.
59func FontHandler() http.Handler {
60 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
61 name := strings.TrimPrefix(r.URL.Path, FontPrefix)
62 var body []byte
63 var kind string
64 switch {
65 case !strings.HasPrefix(r.URL.Path, FontPrefix):
66 case name == "fonts.css":
67 body, kind = FontCSS(), "text/css; charset=utf-8"
68 case name == "onest-latin.woff2":
69 body, _ = fontFS.ReadFile("fonts/onest-latin.woff2")
70 kind = "font/woff2"
71 }
72 if body == nil {
73 http.NotFound(w, r)
74 return
75 }
76 if r.Method != http.MethodGet && r.Method != http.MethodHead {
77 w.Header().Set("Allow", "GET, HEAD")
78 http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
79 return
80 }
81 w.Header().Set("Content-Type", kind)
82 w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
83 w.Header().Set("X-Content-Type-Options", "nosniff")
84 if r.Method == http.MethodHead {
85 return
86 }
87 _, _ = w.Write(body)
88 })
89}
90