-
+
+
Parsimony
diff --git a/admin/src/pages/LoginPage.tsx b/admin/src/pages/LoginPage.tsx
index 6b1c4c1..2ef9a4a 100644
--- a/admin/src/pages/LoginPage.tsx
+++ b/admin/src/pages/LoginPage.tsx
@@ -33,7 +33,8 @@ export function LoginPage() {
}
return (
-
+
+
diff --git a/assets/assets.go b/assets/assets.go
new file mode 100644
index 0000000..c182dd7
--- /dev/null
+++ b/assets/assets.go
@@ -0,0 +1,19 @@
+// Package assets holds the Parsimony logo. The files are generated by make-logo.py.
+package assets
+
+import _ "embed"
+
+// Mark is the square mark: an envelope in a rounded square. It is also the favicon.
+//
+//go:embed logo-mark.svg
+var Mark string
+
+// Logo is the mark with the wordmark, for light backgrounds.
+//
+//go:embed logo.svg
+var Logo string
+
+// LogoDark is the mark with the wordmark, for dark backgrounds.
+//
+//go:embed logo-dark.svg
+var LogoDark string
diff --git a/assets/assets_test.go b/assets/assets_test.go
new file mode 100644
index 0000000..2a1db66
--- /dev/null
+++ b/assets/assets_test.go
@@ -0,0 +1,123 @@
+package assets
+
+import (
+ "bytes"
+ "encoding/xml"
+ "io"
+ "os"
+ "strings"
+ "testing"
+)
+
+var files = map[string]string{"logo-mark.svg": Mark, "logo.svg": Logo, "logo-dark.svg": LogoDark}
+
+func TestLogosAreWellFormedSVG(t *testing.T) {
+ for name, src := range files {
+ if src == "" {
+ t.Fatalf("%s is empty", name)
+ }
+ dec := xml.NewDecoder(strings.NewReader(src))
+ var root *xml.StartElement
+ for {
+ tok, err := dec.Token()
+ if err == io.EOF {
+ break
+ }
+ if err != nil {
+ t.Fatalf("%s: %v", name, err)
+ }
+ if se, ok := tok.(xml.StartElement); ok && root == nil {
+ se := se
+ root = &se
+ }
+ }
+ if root == nil || root.Name.Local != "svg" || root.Name.Space != "http://www.w3.org/2000/svg" {
+ t.Fatalf("%s: root element %+v", name, root)
+ }
+ attrs := map[string]string{}
+ for _, a := range root.Attr {
+ attrs[a.Name.Local] = a.Value
+ }
+ if attrs["viewBox"] == "" || attrs["role"] != "img" || attrs["aria-label"] != "Parsimony" {
+ t.Errorf("%s: it must scale (viewBox) and be named for screen readers: %v", name, attrs)
+ }
+ if attrs["width"] != "" || attrs["height"] != "" {
+ t.Errorf("%s: no fixed size: the page decides", name)
+ }
+ }
+}
+
+func TestLogosNeedNothingFromOutside(t *testing.T) {
+ // Inline in a page with a strict CSP, in a README, on a dark background: no fonts, scripts, images or links.
+ for name, src := range files {
+ for _, bad := range []string{" 4000 {
+ t.Errorf("%s is %d bytes: a logo should stay tiny", name, len(src))
+ }
+ }
+}
+
+func TestTheWordmarkLogosDifferOnlyInColour(t *testing.T) {
+ strip := func(s string) string {
+ for _, c := range []string{"#0f172a", "#ffffff", "#0f766e", "#2dd4bf"} {
+ s = strings.ReplaceAll(s, c, "#")
+ }
+ return s
+ }
+ if strip(Logo) != strip(LogoDark) {
+ t.Fatal("the light and dark logos must have the same shapes")
+ }
+ if Logo == LogoDark {
+ t.Fatal("the dark logo must use light colours")
+ }
+ if !strings.Contains(LogoDark, "#ffffff") || strings.Contains(LogoDark, "#0f172a") {
+ t.Fatal("the dark logo draws the letters in white, not in the dark ink")
+ }
+ if !strings.Contains(Logo, "#0f172a") {
+ t.Fatal("the light logo draws the letters in the dark ink")
+ }
+}
+
+func TestTheAdminUIShipsTheSameLogos(t *testing.T) {
+ for public, want := range map[string]string{"../admin/public/favicon.svg": Mark, "../admin/public/logo.svg": Logo} {
+ got, err := os.ReadFile(public)
+ if err != nil {
+ t.Fatalf("%s: %v (copy it from assets/)", public, err)
+ }
+ if !bytes.Equal(got, []byte(want)) {
+ t.Errorf("%s differs from the file in assets/: run `python3 assets/make-logo.py assets` and copy it", public)
+ }
+ }
+}
+
+// The mark is white on teal: that pair must stay readable (WCAG AA for graphics asks 3:1).
+func TestTheMarkHasEnoughContrast(t *testing.T) {
+ lum := func(hex string) float64 {
+ var r, g, b int
+ if _, err := fmtSscanf(hex, &r, &g, &b); err != nil {
+ t.Fatal(err)
+ }
+ f := func(c int) float64 {
+ v := float64(c) / 255
+ if v <= 0.03928 {
+ return v / 12.92
+ }
+ return pow((v+0.055)/1.055, 2.4)
+ }
+ return 0.2126*f(r) + 0.7152*f(g) + 0.0722*f(b)
+ }
+ l1, l2 := lum("#ffffff"), lum("#0f766e")
+ if ratio := (l1 + 0.05) / (l2 + 0.05); ratio < 4.5 {
+ t.Fatalf("contrast %.2f:1", ratio)
+ }
+ if !strings.Contains(Mark, "#0f766e") || !strings.Contains(Mark, "#ffffff") {
+ t.Fatal("the contrast test checks the colours the mark really uses")
+ }
+}
diff --git a/assets/helpers_test.go b/assets/helpers_test.go
new file mode 100644
index 0000000..1d9e79e
--- /dev/null
+++ b/assets/helpers_test.go
@@ -0,0 +1,11 @@
+package assets
+
+import (
+ "fmt"
+ "math"
+)
+
+func fmtSscanf(hex string, r, g, b *int) (int, error) {
+ return fmt.Sscanf(hex, "#%02x%02x%02x", r, g, b)
+}
+func pow(x, y float64) float64 { return math.Pow(x, y) }
diff --git a/assets/logo-dark.svg b/assets/logo-dark.svg
new file mode 100644
index 0000000..09d7633
--- /dev/null
+++ b/assets/logo-dark.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/assets/logo-mark-512.png b/assets/logo-mark-512.png
new file mode 100644
index 0000000..3e6d237
Binary files /dev/null and b/assets/logo-mark-512.png differ
diff --git a/assets/logo-mark.svg b/assets/logo-mark.svg
new file mode 100644
index 0000000..c9ca516
--- /dev/null
+++ b/assets/logo-mark.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/assets/logo.png b/assets/logo.png
new file mode 100644
index 0000000..b7291a3
Binary files /dev/null and b/assets/logo.png differ
diff --git a/assets/logo.svg b/assets/logo.svg
new file mode 100644
index 0000000..e7df26e
--- /dev/null
+++ b/assets/logo.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/assets/make-logo.py b/assets/make-logo.py
new file mode 100644
index 0000000..35a9e72
--- /dev/null
+++ b/assets/make-logo.py
@@ -0,0 +1,85 @@
+# Generates the Parsimony logo files: python3 assets/make-logo.py assets
+# The wordmark is drawn with monoline strokes, not typeset: it needs no font and looks the same everywhere.
+# The mark is an envelope in a rounded square; the dot of the i echoes it in the accent colour.
+import math, sys
+
+INK, TEAL, WHITE = "#0f172a", "#0f766e", "#ffffff"
+SW = 4.4 # stroke width of the letters
+H = 24 # x-height
+B = 40 # baseline y in the wordmark box
+T = B - H
+GAP = 8.5
+
+def circle(cx, cy, r): return f' '
+def path(d): return f' '
+
+def letter(ch):
+ """returns (svg elements, advance width) with x from 0"""
+ if ch == "o": return circle(12, B-12, 12), 24
+ if ch == "a": return circle(12, B-12, 12) + path(f"M24 {T}V{B}"), 24
+ if ch == "p": return path(f"M0 {T}V{B+14}") + circle(12, B-12, 12), 24
+ if ch == "n": return path(f"M0 {T}V{B}") + path(f"M0 {T+12}A12 12 0 0 1 24 {T+12}V{B}"), 24
+ if ch == "m": return path(f"M0 {T}V{B}") + path(f"M0 {T+10}A10 10 0 0 1 20 {T+10}V{B}") + path(f"M20 {T+10}A10 10 0 0 1 40 {T+10}V{B}"), 40
+ if ch == "r": return path(f"M0 {T}V{B}") + path(f"M0 {T+13}A13 13 0 0 1 13 {T}"), 13
+ if ch == "i": return path(f"M0 {T}V{B}") + f' ', 0
+ if ch == "y": return path(f"M0 {T}L12.6 {B}") + path(f"M24 {T}L6 {B+14}"), 24
+ if ch == "s":
+ d = (f"M18 {T+5}C15 {T+1} 11 {T} 9 {T}C4 {T} 2 {T+3.5} 2 {T+6.5}C2 {T+11} 7 {T+12} 10.5 {T+13}"
+ f"C15 {T+14} 18 {T+16} 18 {T+19}C18 {T+22.5} 14 {B} 9 {B}C5 {B} 2 {B-1.5} 1 {B-5}")
+ return path(d), 18
+ raise ValueError(ch)
+
+def wordmark(text="parsimony"):
+ kern = {("r", "s"): -4.0, ("p", "a"): -0.5}
+ x = 0; out = []; prev = None
+ for ch in text:
+ x += kern.get((prev, ch), 0)
+ svg, w = letter(ch)
+ out.append(f'{svg} ')
+ x += w + GAP
+ prev = ch
+ return "".join(out), x - GAP
+
+def envelope(cx, cy, w=30, h=22, sw=4):
+ """envelope outline with its flap, centred on cx,cy"""
+ x0, y0, x1, y1 = cx-w/2, cy-h/2, cx+w/2, cy+h/2
+ f = lambda v: f"{v:g}"
+ return (f' '
+ f' ')
+
+def mark_svg(bg=True, fg=WHITE, bgc=TEAL):
+ s = f''
+ if bg: s += f' '
+ s += f'{envelope(32, 33, 32, 24)} '
+ s += ' '
+ return s
+
+def logo_svg(dark=False):
+ ink = WHITE if dark else INK
+ teal = "#2dd4bf" if dark else TEAL
+ wm, ww = wordmark()
+ gap = 22
+ scale = 1.0
+ mark = 56
+ total_w = mark + gap + ww + 4
+ # vertical: mark centred on the x-height band of the wordmark
+ top = T - 14 - 2.2 # i-dot top
+ bottom = B + 14 + 2.2 # descenders
+ h = bottom - top
+ my = (h - mark) / 2
+ tx = mark + gap + 2.2
+ ty = -top
+ s = (f''
+ f''
+ f' '
+ f'{envelope(32,33,32,24)} '
+ f'{wm} '
+ f' ')
+ s = s.replace('class="dot"', f'stroke="{teal}"')
+ return s
+
+if __name__ == "__main__":
+ out = sys.argv[1]
+ open(f"{out}/logo.svg","w").write(logo_svg(False))
+ open(f"{out}/logo-dark.svg","w").write(logo_svg(True))
+ open(f"{out}/logo-mark.svg","w").write(mark_svg())
diff --git a/internal/web/web.go b/internal/web/web.go
index 53d36dc..1ed7d0f 100644
--- a/internal/web/web.go
+++ b/internal/web/web.go
@@ -3,6 +3,7 @@ package web
import (
"bytes"
+ "encoding/base64"
"errors"
"html/template"
"log"
@@ -12,6 +13,7 @@ import (
"strings"
"time"
+ "codeberg.org/squidd/parsimony/assets"
"codeberg.org/squidd/parsimony/internal/archive"
"codeberg.org/squidd/parsimony/internal/router"
"codeberg.org/squidd/parsimony/internal/store"
@@ -19,6 +21,9 @@ import (
const pageSize = 25
+// faviconURL is the logo as a data: URI, the only kind of image the CSP allows.
+var faviconURL = "data:image/svg+xml;base64," + base64.StdEncoding.EncodeToString([]byte(assets.Mark))
+
type server struct {
store *store.Store
router *router.Router
@@ -29,7 +34,10 @@ type server struct {
func New(s *store.Store, rt *router.Router) http.Handler {
srv := &server{store: s, router: rt, tmpl: template.Must(template.New("").Funcs(template.FuncMap{
"hide": archive.Obfuscate,
- "date": func(t time.Time) string { return t.UTC().Format("2006-01-02 15:04") },
+ // The logo is a trusted static asset: inline, so the strict CSP needs no image source for it.
+ "mark": func() template.HTML { return template.HTML(assets.Mark) },
+ "favicon": func() template.URL { return template.URL(faviconURL) },
+ "date": func(t time.Time) string { return t.UTC().Format("2006-01-02 15:04") },
}).Parse(templates))}
mux := http.NewServeMux()
@@ -48,7 +56,7 @@ func New(s *store.Store, rt *router.Router) http.Handler {
func secure(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
h := w.Header()
- h.Set("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'")
+ h.Set("Content-Security-Policy", "default-src 'none'; img-src data:; style-src 'unsafe-inline'; form-action 'self'; base-uri 'none'; frame-ancestors 'none'")
h.Set("X-Content-Type-Options", "nosniff")
h.Set("Referrer-Policy", "no-referrer")
h.Set("Content-Type", "text/html; charset=utf-8")
@@ -238,6 +246,7 @@ const templates = `
{{define "head"}}
{{.}}
+
{{end}}
+.brand{display:inline-block;margin-bottom:1rem}
+.brand svg{width:2rem;height:2rem;display:block}
+
+{{mark}} {{end}}
{{define "foot"}}{{end}}
{{define "index"}}{{template "head" "Mailing list archives"}}
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index bbdd4c4..2e517f5 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -1,7 +1,9 @@
package web
import (
+ "encoding/base64"
"fmt"
+ "html"
"net/http"
"net/http/httptest"
"net/url"
@@ -9,6 +11,7 @@ import (
"testing"
"time"
+ "codeberg.org/squidd/parsimony/assets"
"codeberg.org/squidd/parsimony/internal/router"
"codeberg.org/squidd/parsimony/internal/store"
)
@@ -289,3 +292,35 @@ func TestUnsubscribeOneClickBodyIsAccepted(t *testing.T) {
t.Fatal("bob must be unsubscribed")
}
}
+
+func TestEveryPageCarriesTheLogoAndTheFavicon(t *testing.T) {
+ f := newFixture(t)
+ id := f.add(t, f.pub.ID, "<1@x>", "Hello", "A", "body", 1_700_000_000, "")
+ favicon := "data:image/svg+xml;base64," + base64.StdEncoding.EncodeToString([]byte(assets.Mark))
+ for _, p := range []string{"/", "/archive/dev@example.org", fmt.Sprintf("/archive/dev@example.org/%d", id), "/unsubscribe/" + f.bobTok, "/nope"} {
+ rec := get(t, f.h, p)
+ body := html.UnescapeString(rec.Body.String()) // html/template writes "+" in an attribute as +
+ if !strings.Contains(body, ``) {
+ t.Errorf("%s: no inline logo", p)
+ }
+ if !strings.Contains(body, ` `) {
+ t.Errorf("%s: no favicon (a data: URI, because the CSP allows nothing else)", p)
+ }
+ if !strings.Contains(body, ``) {
+ t.Errorf("%s: the logo must lead back to the index", p)
+ }
+ }
+}
+
+func TestTheCSPAllowsOnlyDataImages(t *testing.T) {
+ f := newFixture(t)
+ csp := get(t, f.h, "/").Header().Get("Content-Security-Policy")
+ if !strings.Contains(csp, "img-src data:") || !strings.Contains(csp, "default-src 'none'") {
+ t.Fatalf("csp = %q", csp)
+ }
+ for _, loose := range []string{"*", "http:", "https:", "'unsafe-eval'", "script-src"} {
+ if strings.Contains(csp, loose) {
+ t.Errorf("the CSP must stay strict, it contains %q: %s", loose, csp)
+ }
+ }
+}