refactor(brand): generate the frontend logo copy and wordmark geometry

assets/logo.svg was duplicated byte for byte in frontend/public, and WordmarkLoader hand-copied the ten wordmark strokes from the Python generator, so the icon and the lettering could drift silently.

scripts/brand/wordmark.py now writes frontend/public/logo.svg and frontend/src/components/wordmark.gen.ts, and the loader imports that geometry. The unreferenced assets/wordmark-*.svg outputs are gone, and frontend/scripts/test-brand.mjs fails when either copy is edited by hand.
This commit is contained in:
千川白浪 committed 2026-12-04 23:24:36 -07:00
1 parent 87e7ac8774
commit f4395a1f28
7 files changed
+161 -48

No files matched your search

+1
View File
@@ -2,6 +2,7 @@
"exclude": [
"frontend/wailsjs/**",
"frontend/src/i18n/domains/*.gen.ts",
"frontend/src/components/*.gen.ts",
"go.sum",
"**/package-lock.json",
"**/pnpm-lock.yaml"
-1
View File
@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 539 141" width="539" height="141" role="img" aria-label="Reims-Go"><g transform="translate(4 107)"><defs><linearGradient id="wm" gradientUnits="userSpaceOnUse" x1="376" y1="0" x2="531" y2="0"><stop offset="0" stop-color="#3b8cff"/><stop offset="0.5" stop-color="#6d5dfc"/><stop offset="1" stop-color="#ff7a9a"/></linearGradient><linearGradient id="wmb" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#ffd43b"/><stop offset="1" stop-color="#ff9f0a"/></linearGradient></defs><g fill="none" stroke-width="15" stroke-linecap="round" stroke-linejoin="round"><path d="M7.5 -7.5V-36A24 28.5 0 0 1 31.5 -64.5" stroke="#f4f5fa"/><path d="M50.5 -36H107.5A28.5 28.5 0 1 0 100.18 -16.93" stroke="#f4f5fa"/><path d="M133.5 -64.5V-7.5" stroke="#f4f5fa"/><circle cx="133.5" cy="-94" r="9" fill="#ff7a9a"/><path d="M159.5 -7.5V-36A22 28.5 0 0 1 203.5 -36V-7.5M203.5 -36A22 28.5 0 0 1 247.5 -36V-7.5" stroke="#f4f5fa"/><path d="M311.05 -59.02A21 14.25 0 0 0 273.5 -50.25A21 14.25 0 0 0 294.5 -36A21 14.25 0 0 1 315.5 -21.75A21 14.25 0 0 1 277.95 -12.98" stroke="#f4f5fa"/><path d="M340.5 -36H358.5" stroke="#5d6382"/><path d="M440.5 -36A28.5 28.5 0 1 1 440.5 -36.01" stroke="url(#wm)"/><path d="M440.5 -64.5V0A28.5 22.5 0 0 1 387.32 11.25" stroke="url(#wm)"/><path d="M523.5 -36A28.5 28.5 0 1 1 523.5 -36.01" stroke="url(#wm)"/></g></g></svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

-1
View File
@@ -1 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 539 141" width="539" height="141" role="img" aria-label="Reims-Go"><g transform="translate(4 107)"><defs><linearGradient id="wm" gradientUnits="userSpaceOnUse" x1="376" y1="0" x2="531" y2="0"><stop offset="0" stop-color="#3b8cff"/><stop offset="0.5" stop-color="#6d5dfc"/><stop offset="1" stop-color="#ff7a9a"/></linearGradient><linearGradient id="wmb" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#ffd43b"/><stop offset="1" stop-color="#ff9f0a"/></linearGradient></defs><g fill="none" stroke-width="15" stroke-linecap="round" stroke-linejoin="round"><path d="M7.5 -7.5V-36A24 28.5 0 0 1 31.5 -64.5" stroke="#16182e"/><path d="M50.5 -36H107.5A28.5 28.5 0 1 0 100.18 -16.93" stroke="#16182e"/><path d="M133.5 -64.5V-7.5" stroke="#16182e"/><circle cx="133.5" cy="-94" r="9" fill="#ff7a9a"/><path d="M159.5 -7.5V-36A22 28.5 0 0 1 203.5 -36V-7.5M203.5 -36A22 28.5 0 0 1 247.5 -36V-7.5" stroke="#16182e"/><path d="M311.05 -59.02A21 14.25 0 0 0 273.5 -50.25A21 14.25 0 0 0 294.5 -36A21 14.25 0 0 1 315.5 -21.75A21 14.25 0 0 1 277.95 -12.98" stroke="#16182e"/><path d="M340.5 -36H358.5" stroke="#a3a8bf"/><path d="M440.5 -36A28.5 28.5 0 1 1 440.5 -36.01" stroke="url(#wm)"/><path d="M440.5 -64.5V0A28.5 22.5 0 0 1 387.32 11.25" stroke="url(#wm)"/><path d="M523.5 -36A28.5 28.5 0 1 1 523.5 -36.01" stroke="url(#wm)"/></g></g></svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

+21
View File
@@ -0,0 +1,21 @@
// scripts/brand/wordmark.py is the single source of the icon and the wordmark
// geometry: it copies assets/logo.svg into public/ and generates
// wordmark.gen.ts. Neither copy may be edited by hand.
import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
const repoRoot = path.resolve(import.meta.dirname, '..', '..')
test('frontend/public/logo.svg is the copy of assets/logo.svg', () => {
const source = fs.readFileSync(path.join(repoRoot, 'assets', 'logo.svg'))
const served = fs.readFileSync(path.join(repoRoot, 'frontend', 'public', 'logo.svg'))
assert.ok(source.equals(served), 'run python scripts/brand/wordmark.py to refresh frontend/public/logo.svg')
})
test('the frontend wordmark geometry is generated', () => {
const generated = fs.readFileSync(path.join(repoRoot, 'frontend', 'src', 'components', 'wordmark.gen.ts'), 'utf8')
assert.match(generated, /^\/\/ Code generated by scripts\/brand\/wordmark\.py; DO NOT EDIT\./)
assert.match(generated, /export const WORDMARK_STROKES: WordmarkStroke\[\] = \[/)
})
+17 -26
View File
@@ -1,23 +1,14 @@
import React, { useEffect, useId, useRef } from 'react'
import {
WORDMARK_GRADIENT,
WORDMARK_ORIGIN,
WORDMARK_STROKES,
WORDMARK_STROKE_WIDTH,
WORDMARK_VIEWBOX,
} from './wordmark.gen'
// Strokes of the Reims-Go wordmark (scripts/brand/wordmark.py), in pen order.
// Coordinates sit in the generator's baseline frame (translate 4 107).
type Stroke =
| { kind: 'path'; d: string; ink: 'ink' | 'dash' | 'brand' }
| { kind: 'dot'; cx: number; cy: number; r: number }
const STROKES: Stroke[] = [
{ kind: 'path', ink: 'ink', d: 'M7.5 -7.5V-36A24 28.5 0 0 1 31.5 -64.5' },
{ kind: 'path', ink: 'ink', d: 'M50.5 -36H107.5A28.5 28.5 0 1 0 100.18 -16.93' },
{ kind: 'path', ink: 'ink', d: 'M133.5 -64.5V-7.5' },
{ kind: 'dot', cx: 133.5, cy: -94, r: 9 },
{ kind: 'path', ink: 'ink', d: 'M159.5 -7.5V-36A22 28.5 0 0 1 203.5 -36V-7.5M203.5 -36A22 28.5 0 0 1 247.5 -36V-7.5' },
{ kind: 'path', ink: 'ink', d: 'M311.05 -59.02A21 14.25 0 0 0 273.5 -50.25A21 14.25 0 0 0 294.5 -36A21 14.25 0 0 1 315.5 -21.75A21 14.25 0 0 1 277.95 -12.98' },
{ kind: 'path', ink: 'dash', d: 'M340.5 -36H358.5' },
{ kind: 'path', ink: 'brand', d: 'M440.5 -36A28.5 28.5 0 1 1 440.5 -36.01' },
{ kind: 'path', ink: 'brand', d: 'M440.5 -64.5V0A28.5 22.5 0 0 1 387.32 11.25' },
{ kind: 'path', ink: 'brand', d: 'M523.5 -36A28.5 28.5 0 1 1 523.5 -36.01' },
]
// Geometry comes from scripts/brand/wordmark.py through wordmark.gen.ts: the
// strokes are in pen order, in the generator's baseline frame.
// Pen timing, in ms. Writing speed is constant, so long strokes take longer.
const PX_PER_MS = 0.62
@@ -101,20 +92,20 @@ export const WordmarkLoader: React.FC<Props> = ({ width = 168, label, className
<svg
ref={svgRef}
className="wordmark-loader-svg"
viewBox="0 0 539 141"
viewBox={`0 0 ${WORDMARK_VIEWBOX.width} ${WORDMARK_VIEWBOX.height}`}
width={width}
height={Math.round((width * 141) / 539)}
height={Math.round((width * WORDMARK_VIEWBOX.height) / WORDMARK_VIEWBOX.width)}
aria-hidden="true"
>
<defs>
<linearGradient id={gid} gradientUnits="userSpaceOnUse" x1="376" y1="0" x2="531" y2="0">
<stop offset="0" stopColor="#3b8cff" />
<stop offset="0.5" stopColor="#6d5dfc" />
<stop offset="1" stopColor="#ff7a9a" />
<linearGradient id={gid} gradientUnits="userSpaceOnUse" x1={WORDMARK_GRADIENT.x1} y1="0" x2={WORDMARK_GRADIENT.x2} y2="0">
{WORDMARK_GRADIENT.stops.map((color, i) => (
<stop key={color} offset={i / (WORDMARK_GRADIENT.stops.length - 1)} stopColor={color} />
))}
</linearGradient>
</defs>
<g transform="translate(4 107)" fill="none" strokeWidth="15" strokeLinecap="round" strokeLinejoin="round">
{STROKES.map((s, i) => s.kind === 'dot' ? (
<g transform={`translate(${WORDMARK_ORIGIN.x} ${WORDMARK_ORIGIN.y})`} fill="none" strokeWidth={WORDMARK_STROKE_WIDTH} strokeLinecap="round" strokeLinejoin="round">
{WORDMARK_STROKES.map((s, i) => s.kind === 'dot' ? (
<circle
key={i}
data-stroke=""
+33
View File
@@ -0,0 +1,33 @@
// Code generated by scripts/brand/wordmark.py; DO NOT EDIT.
// Run "python scripts/brand/wordmark.py" after changing the wordmark.
export type WordmarkInk = 'ink' | 'dash' | 'brand'
export type WordmarkStroke =
| { kind: 'path'; ink: WordmarkInk; d: string }
| { kind: 'dot'; cx: number; cy: number; r: number }
/** viewBox of the wordmark, in generator units. */
export const WORDMARK_VIEWBOX = { width: 539, height: 141 }
/** Translation that puts the generator's baseline frame into the viewBox. */
export const WORDMARK_ORIGIN = { x: 4, y: 107 }
export const WORDMARK_STROKE_WIDTH = 15
/** Horizontal extent of the brand gradient on the baseline. */
export const WORDMARK_GRADIENT = { x1: 376, x2: 531, stops: ['#3b8cff', '#6d5dfc', '#ff7a9a'] }
/** Strokes in pen order, in the generator's baseline frame. */
export const WORDMARK_STROKES: WordmarkStroke[] = [
{ kind: 'path', ink: 'ink', d: 'M7.5 -7.5V-36A24 28.5 0 0 1 31.5 -64.5' },
{ kind: 'path', ink: 'ink', d: 'M50.5 -36H107.5A28.5 28.5 0 1 0 100.18 -16.93' },
{ kind: 'path', ink: 'ink', d: 'M133.5 -64.5V-7.5' },
{ kind: 'dot', cx: 133.5, cy: -94, r: 9 },
{ kind: 'path', ink: 'ink', d: 'M159.5 -7.5V-36A22 28.5 0 0 1 203.5 -36V-7.5M203.5 -36A22 28.5 0 0 1 247.5 -36V-7.5' },
{ kind: 'path', ink: 'ink', d: 'M311.05 -59.02A21 14.25 0 0 0 273.5 -50.25A21 14.25 0 0 0 294.5 -36A21 14.25 0 0 1 315.5 -21.75A21 14.25 0 0 1 277.95 -12.98' },
{ kind: 'path', ink: 'dash', d: 'M340.5 -36H358.5' },
{ kind: 'path', ink: 'brand', d: 'M440.5 -36A28.5 28.5 0 1 1 440.5 -36.01' },
{ kind: 'path', ink: 'brand', d: 'M440.5 -64.5V0A28.5 22.5 0 0 1 387.32 11.25' },
{ kind: 'path', ink: 'brand', d: 'M523.5 -36A28.5 28.5 0 1 1 523.5 -36.01' },
]
+89 -20
View File
@@ -1,4 +1,4 @@
"""Draws the Reims-Go wordmark and README banners.
"""Draws the Reims-Go wordmark, the README banners and the frontend wordmark data.
The wordmark is monoline lettering: one stroke width, round caps, built
from circles, ellipses and straight lines so it matches the rounded app
@@ -6,8 +6,15 @@ icon. Run from the repository root:
python scripts/brand/wordmark.py
It writes assets/wordmark-{light,dark}.svg and
.github/readme/banner-{light,dark}.svg. It needs only the standard library.
It writes .github/readme/banner-{light,dark}.svg,
frontend/src/components/wordmark.gen.ts and frontend/public/logo.svg, and
needs only the standard library.
assets/logo.svg is the source of the icon: this script copies it to
frontend/public/logo.svg and embeds it in the banners. The raster icons
assets/logo.png (embedded by main.go for the tray), build/appicon.png and
build/windows/icon.ico are exported from the same artwork by hand, so
re-export them whenever assets/logo.svg changes.
"""
import math
@@ -22,6 +29,13 @@ MUTED = {"light": "#a3a8bf", "dark": "#5d6382"}
GRADIENT = ("#3b8cff", "#6d5dfc", "#ff7a9a")
BOLT = ("#ffd43b", "#ff9f0a")
PAD = 4 # margin around the wordmark frame
# Roles the frontend loader can paint: CSS classes plus the brand gradient.
TS_INK = {"ink": "ink", "muted": "dash", "go": "brand"}
PATH_ELEMENT = re.compile(r'^<path d="([^"]+)"$')
CIRCLE_ELEMENT = re.compile(r'^<circle cx="([^"]+)" cy="([^"]+)" r="([^"]+)"$')
# The style the script writes. Variants used while choosing it:
# joiner: "dash" | "bolt" | "none"; go: "gradient" | "pill"
# dot: "accent" | "ink"; stroke: stroke width.
@@ -104,7 +118,12 @@ def g_o(g, x):
def wordmark(theme, style=STYLE, gid="wm"):
"""Returns (svg body, width, ascent, descent); the baseline is y=0."""
"""Lays the wordmark out on the baseline y=0.
Returns a dict with the painted svg body, the total width, the ascent and
descent, the unpainted (role, element) strokes in pen order, and the x where
the "go" gradient starts.
"""
g = Geo(style["stroke"])
joiner = {"dash": [(g_dash, 10)], "bolt": [(g_bolt, 8)], "none": []}[style["joiner"]]
pill = style["go"] == "pill"
@@ -116,12 +135,13 @@ def wordmark(theme, style=STYLE, gid="wm"):
"bolt": f'fill="url(#{gid}b)" stroke="none"',
"go": 'stroke="#ffffff"' if pill else f'stroke="url(#{gid})"',
}
out, x, go0 = [], 0.0, None
out, strokes, x, go0 = [], [], 0.0, None
for draw, gap in seq:
if draw is g_g:
go0 = x + (14 if pill else 0)
x = go0
width, parts = draw(g, x)
strokes += parts
out += [f"{el} {paint[role]}/>" for role, el in parts]
x += width + gap
asc, desc = X + 22 + g.H + 1.5, 22.5 + g.H
@@ -139,34 +159,83 @@ def wordmark(theme, style=STYLE, gid="wm"):
f'<linearGradient id="{gid}b" x1="0" y1="0" x2="0" y2="1">{bolt}</linearGradient></defs>')
body = (f'{defs}{pill_el}<g fill="none" stroke-width="{f(g.W)}" stroke-linecap="round" '
f'stroke-linejoin="round">{"".join(out)}</g>')
return body, x, asc, desc
def standalone(theme, style=STYLE):
body, width, asc, desc = wordmark(theme, style)
pad = 4
w, h = width + 2 * pad, asc + desc + 2 * pad
return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {f(w)} {f(h)}" width="{f(w)}" '
f'height="{f(h)}" role="img" aria-label="Reims-Go"><g transform="translate({pad} {f(pad + asc)})">'
f'{body}</g></svg>\n')
return dict(body=body, width=x, ascent=asc, descent=desc, strokes=strokes, go_start=go0, pill=pill)
def banner(theme, style=STYLE):
logo = (ROOT / "assets/logo.svg").read_text(encoding="utf-8")
icon_body = re.sub(r"^.*?<svg[^>]*>", "", logo, flags=re.S).rsplit("</svg>", 1)[0]
body, width, _, _ = wordmark(theme, style)
wm = wordmark(theme, style)
icon, gap = 180, 26
w = icon + gap + width + 6
w = icon + gap + wm["width"] + 6
return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {f(w)} {icon}" width="{f(w)}" '
f'height="{icon}" role="img" aria-label="Reims-Go">'
f'<svg x="0" y="0" width="{icon}" height="{icon}" viewBox="0 0 1024 1024">{icon_body}</svg>'
f'<g transform="translate({icon + gap} {f(icon / 2 + X / 2)})">{body}</g></svg>\n')
f'<g transform="translate({icon + gap} {f(icon / 2 + X / 2)})">{wm["body"]}</g></svg>\n')
def ts_strokes(strokes):
"""Turns the unpainted (role, element) strokes into TypeScript literals."""
lines = []
for role, el in strokes:
circle = CIRCLE_ELEMENT.match(el)
if circle:
cx, cy, r = circle.groups()
lines.append(f" {{ kind: 'dot', cx: {cx}, cy: {cy}, r: {r} }},")
continue
path = PATH_ELEMENT.match(el)
if path is None or role not in TS_INK:
raise ValueError(f"the frontend loader cannot paint stroke {el!r} with role {role!r}")
lines.append(f" {{ kind: 'path', ink: '{TS_INK[role]}', d: '{path.group(1)}' }},")
return "\n".join(lines)
def ts_module(style=STYLE):
"""Writes the geometry the frontend WordmarkLoader animates.
The loader paints strokes with CSS classes and one gradient, so it needs
the geometry and the gradient extent, not the per-theme colours.
"""
wm = wordmark("light", style)
width, height = wm["width"] + 2 * PAD, wm["ascent"] + wm["descent"] + 2 * PAD
gradient_x1 = wm["go_start"] - (14 if wm["pill"] else 0)
stops = ", ".join(f"'{c}'" for c in GRADIENT)
return (
"// Code generated by scripts/brand/wordmark.py; DO NOT EDIT.\n"
"// Run \"python scripts/brand/wordmark.py\" after changing the wordmark.\n"
"\n"
"export type WordmarkInk = 'ink' | 'dash' | 'brand'\n"
"\n"
"export type WordmarkStroke =\n"
" | { kind: 'path'; ink: WordmarkInk; d: string }\n"
" | { kind: 'dot'; cx: number; cy: number; r: number }\n"
"\n"
"/** viewBox of the wordmark, in generator units. */\n"
f"export const WORDMARK_VIEWBOX = {{ width: {f(width)}, height: {f(height)} }}\n"
"\n"
"/** Translation that puts the generator's baseline frame into the viewBox. */\n"
f"export const WORDMARK_ORIGIN = {{ x: {PAD}, y: {f(PAD + wm['ascent'])} }}\n"
"\n"
f"export const WORDMARK_STROKE_WIDTH = {f(style['stroke'])}\n"
"\n"
"/** Horizontal extent of the brand gradient on the baseline. */\n"
f"export const WORDMARK_GRADIENT = {{ x1: {f(gradient_x1)}, x2: {f(wm['width'])}, stops: [{stops}] }}\n"
"\n"
"/** Strokes in pen order, in the generator's baseline frame. */\n"
"export const WORDMARK_STROKES: WordmarkStroke[] = [\n"
f"{ts_strokes(wm['strokes'])}\n"
"]\n"
)
def main():
# Text outputs use the platform line endings so a rerun leaves the working
# tree clean under core.autocrlf=true as well as on Linux.
for theme in ("light", "dark"):
(ROOT / f"assets/wordmark-{theme}.svg").write_text(standalone(theme), encoding="utf-8", newline="\n")
(ROOT / f".github/readme/banner-{theme}.svg").write_text(banner(theme), encoding="utf-8", newline="\n")
(ROOT / f".github/readme/banner-{theme}.svg").write_text(banner(theme), encoding="utf-8")
(ROOT / "frontend/src/components/wordmark.gen.ts").write_text(ts_module(), encoding="utf-8")
# The frontend serves the icon from public/, so keep that copy byte-identical.
(ROOT / "frontend/public/logo.svg").write_bytes((ROOT / "assets/logo.svg").read_bytes())
if __name__ == "__main__":