自建 Gitea 此前是出厂外观(茶杯标 + 「Gitea: Git with a cup of tea」标题),而品牌「纯字标 + 朱砂条」已在官网落地;同时现网 1.27.2 落后两个安全版本 —— 1.27.3 的 fix(git): restrict hook permissions 打的正是本实例 8 月被入侵所用的 packObjectsHook 向量。装饰基准取自升级后从容器抽出的真实模板,不凭记忆手写。 - 升级 28.2.0:pg_dump 后还原到一次性探针库对账(116 表 / 20 仓库 / 8 用户全等),停服 8s;28.0.0 的 git egress BREAKING 按裁定收为 EGRESS_MODE=strict(实测 app.ini 无旧 ALLOWED_* 键、mirror 仓库 0 个 ⇒ 空白名单不伤业务)。 - 装饰层真源入库 infra/cicd/gitea-custom/(结构即实测 CustomPath=/data/gitea):页头/OG/默认头像换简标与刻版、novalon- brand.css 覆盖 --color-primary 全色阶、custom/header.tmpl 外链注入、signin_inner.tmpl 登录页加字标锁定(220×103)。 - 色阶由脚本生成并自带夹具:先对上游 14 档对账(light/dark 两档 ramp 命名互为反向,手敲必错),再喂上游蓝做反向自证,双双通过才写盘。 - 深档按钮改「黑字朱底」:Gitea 用同一令牌既当按钮底色又当链接文字色,AA 区间为空(按钮白字 L≤0.1833 vs 链接 on #1e1f20 L≥0.2362)⇒ #E13C58 × #0D0D0D 实测 4.62:1;深档链接 3.92:1 作为已登记让步保留(上游蓝同位 4.14,本就不达标)。 - deploy/verify 带预检、备份、内容 sha256 比对、负对照与 0/1/2/3 退出码分档,核心判红自动回滚(首轮就靠它把「标题未生效」与「装饰未生效」区分开)。 - 纠正两处生产口径失真:仓库那份「加固版」compose 从未上线(真实文件纳管为 infra/cicd/gitea/docker-compose.live.yml);生产 REQUIRE_SIGNIN_VIEW 实为 false,且 compose 的 DISABLE_REGISTRATION=false 会经 environment-to-ini 在重建时静默打开注册 —— 已对齐为 true。遗留的匿名浏览面与 SSH_PORT 错配只登记不擅动。
297 lines
11 KiB
Python
297 lines
11 KiB
Python
#!/usr/bin/env python3
|
||
"""生成 Gitea 品牌覆盖 CSS(novalon-brand.css)
|
||
|
||
为什么不手敲色阶:
|
||
1. 上游 light/dark 两档的 ramp 命名是**反向**的 —— 浅色档 dark-N 是压暗、light-N 是提亮;
|
||
深色档正好调了个儿(实测 theme-gitea-dark 里 --color-primary-dark-1 = #548fca 比基色更亮)。
|
||
手敲极易把 hover 做成"变亮"。
|
||
2. ramp 的生成律可以从上游蓝反解并验证:压暗 = l×[0.9,0.8,0.7,0.6,0.4,0.2,0.06],
|
||
提亮 = l + (100−l)×[0.1,0.2,0.3,0.4,0.6,0.8,0.94](对 #4183c4 逐档回算,7/7 命中实测值)。
|
||
|
||
自检三件(缺一不写盘):
|
||
A 覆盖完备:上游定义的每一个 --color-primary* 令牌,两档都必须被我们重定义(否则升级后漏色)。
|
||
B 无蓝残留:产出的每个颜色若 b>r 即判红(我们的朱砂在所有档位都必须是红主导)。
|
||
C 对比度门槛:浅档 primary×白字 ≥4.5;深档 primary×#0d0d0d ≥4.5(2026-10-22 甲方裁定:
|
||
深档按钮改「黑字朱底」,因为单值数学上不可能同时满足按钮白字与链接 on 深底)。
|
||
已知让步:深档链接 on #1e1f20 = 3.92(上游蓝同位 4.14,本来就不达 AA),登记在 DEVIATIONS。
|
||
|
||
反向自证:拿上游蓝当输入跑一遍,B 与 C 必须双双判红。判不红说明仪器是空的。
|
||
"""
|
||
import colorsys
|
||
import os
|
||
import re
|
||
import sys
|
||
|
||
UP = "infra/cicd/gitea-custom/upstream/public/assets/css"
|
||
LIGHT_UP = f"{UP}/theme-gitea-light.CcrYmZOI.css"
|
||
DARK_UP = f"{UP}/theme-gitea-dark.n17NpZ-u.css"
|
||
OUT = "infra/cicd/gitea-custom/public/assets/css/novalon-brand.css"
|
||
|
||
SEAL_PAPER = "#C41E3A" # 品牌手册 §3 纸底朱砂
|
||
SEAL_DEEP = "#E13C58" # 品牌手册 §3 深底朱砂
|
||
UPSTREAM_BLUE = "#4183c4"
|
||
|
||
# 深档按钮文字改近黑(甲方 2026-10-22 裁定「按钮改黑字朱底」)
|
||
DARK_CONTRAST = "#0D0D0D"
|
||
LIGHT_CONTRAST = "#ffffff"
|
||
|
||
DARKEN = [0.9, 0.8, 0.7, 0.6, 0.4, 0.2, 0.06]
|
||
LIGHTEN = [0.1, 0.2, 0.3, 0.4, 0.6, 0.8, 0.94]
|
||
|
||
# 已知且被明确登记的让步:键 = 场景,值 = (实测下限, 理由)
|
||
DEVIATIONS = {
|
||
"dark-link-on-body": {
|
||
"floor": 3.0,
|
||
"note": "深档链接文字 3.92:1 不达正文 AA;上游蓝同位仅 4.14,本项按『不比上游更差 + 达非文本 3:1』放行",
|
||
}
|
||
}
|
||
|
||
|
||
def split(h):
|
||
h = h.lstrip("#")
|
||
return [int(h[i:i + 2], 16) for i in (0, 2, 4)]
|
||
|
||
|
||
def to_hex(rgb):
|
||
return "#%02X%02X%02X" % tuple(max(0, min(255, round(v))) for v in rgb)
|
||
|
||
|
||
def lin(c):
|
||
c /= 255.0
|
||
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
|
||
|
||
|
||
def lum(h):
|
||
r, g, b = split(h)
|
||
return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b)
|
||
|
||
|
||
def ratio(a, b):
|
||
la, lb = lum(a), lum(b)
|
||
return (max(la, lb) + 0.05) / (min(la, lb) + 0.05)
|
||
|
||
|
||
def scale_lightness(hexcol, factor=None, lift=None):
|
||
"""在 HSL 里只动明度,色相与饱和不变(朱砂的色相是品牌资产,不许漂)。"""
|
||
r, g, b = (v / 255.0 for v in split(hexcol))
|
||
h, l, s = colorsys.rgb_to_hls(r, g, b)
|
||
if factor is not None:
|
||
l = l * factor
|
||
else:
|
||
l = l + (1.0 - l) * lift
|
||
return to_hex([v * 255.0 for v in colorsys.hls_to_rgb(h, min(max(l, 0.0), 1.0), s)])
|
||
|
||
|
||
def ramp_down(base):
|
||
return [scale_lightness(base, factor=f) for f in DARKEN]
|
||
|
||
|
||
def ramp_up(base):
|
||
return [scale_lightness(base, lift=t) for t in LIGHTEN]
|
||
|
||
|
||
def alpha_ramp(base):
|
||
return ["%s%02X" % (base, round(n * 255 / 10)) for n in range(1, 10)]
|
||
|
||
|
||
def upstream_tokens(path):
|
||
s = open(path, encoding="utf-8").read()
|
||
return sorted(set(re.findall(r"(--color-primary[a-z0-9-]*)\s*:", s)))
|
||
|
||
|
||
def block(base, contrast, theme):
|
||
"""theme=light:dark-N 压暗、light-N 提亮;theme=dark:上游把两条 ramp 对调了。"""
|
||
down, up = ramp_down(base), ramp_up(base)
|
||
darker, lighter = (down, up) if theme == "light" else (up, down)
|
||
lines = [f" --color-primary: {base};", f" --color-primary-contrast: {contrast};"]
|
||
for i, c in enumerate(darker, start=1):
|
||
lines.append(f" --color-primary-dark-{i}: {c};")
|
||
for i, c in enumerate(lighter, start=1):
|
||
lines.append(f" --color-primary-light-{i}: {c};")
|
||
for i, c in enumerate(alpha_ramp(base), start=1):
|
||
lines.append(f" --color-primary-alpha-{i}0: {c};")
|
||
hover = "dark-1" if theme == "light" else "light-1"
|
||
active = "dark-2" if theme == "light" else "light-2"
|
||
lines.append(f" --color-primary-hover: var(--color-primary-{hover});")
|
||
lines.append(f" --color-primary-active: var(--color-primary-{active});")
|
||
# 装饰用的品牌令牌(朱砂条厚度见下方结构性规则)
|
||
lines.append(f" --color-brand-bar: {base};")
|
||
return "\n".join(lines)
|
||
|
||
|
||
def emit(base_light, base_dark, contrast_light, contrast_dark):
|
||
"""作用域三件套,不能只写 media query:
|
||
Gitea 允许用户在账户设置里显式选主题,此时 <html data-theme> 决定一切(现网实测 gitea-auto),
|
||
系统偏好与所选主题不一致时纯 media query 会判错档。
|
||
特异度::root[data-theme*=...] (0,1,1) > :root (0,0,1) ⇒ 显式选择永远压过默认档。
|
||
用 [data-theme*="dark"] 而非等值匹配,是为了覆盖色弱变体(gitea-dark-tritanopia 等)。"""
|
||
light = block(base_light, contrast_light, "light")
|
||
dark = block(base_dark, contrast_dark, "dark")
|
||
return f"""/* 睿新致遠 / NOVALON · Gitea 品牌覆盖(由 build-brand-css.py 生成,勿手改)
|
||
生成律、作用域口径与判据见该脚本文件头。加载顺序:base/head_style 之后由 custom/header.tmpl
|
||
外链 ⇒ 同特异性下后者胜出,所以这里只重定义令牌,不复制上游规则。 */
|
||
|
||
:root {{
|
||
{light}
|
||
}}
|
||
|
||
@media (prefers-color-scheme: dark) {{
|
||
:root[data-theme*="auto"] {{
|
||
{dark}
|
||
}}
|
||
}}
|
||
|
||
:root[data-theme*="dark"] {{
|
||
{dark}
|
||
}}
|
||
|
||
/* —— 结构性装饰:只用令牌,不写死色值 —— */
|
||
|
||
/* 朱砂条:#navbar 原本是 border-bottom:1px solid var(--color-secondary)(实测上游规则),
|
||
这里换成 3px 朱砂。条厚固定 3px,不随视口缩放 ⇒ 手册「<1px 即禁用」在 375 档同样成立。 */
|
||
#navbar {{
|
||
border-bottom: 3px solid var(--color-brand-bar);
|
||
}}
|
||
|
||
/* 登录页字标锁定:图与深浅档由模板 + 下面两条规则决定,尺寸在模板里给(≥64px 安全档) */
|
||
.novalon-lockup {{
|
||
display: block;
|
||
margin: 0 auto;
|
||
}}
|
||
.novalon-lockup-dark {{
|
||
display: none;
|
||
}}
|
||
@media (prefers-color-scheme: dark) {{
|
||
:root[data-theme*="auto"] .novalon-lockup-light {{
|
||
display: none;
|
||
}}
|
||
:root[data-theme*="auto"] .novalon-lockup-dark {{
|
||
display: block;
|
||
}}
|
||
}}
|
||
:root[data-theme*="dark"] .novalon-lockup-light {{
|
||
display: none;
|
||
}}
|
||
:root[data-theme*="dark"] .novalon-lockup-dark {{
|
||
display: block;
|
||
}}
|
||
"""
|
||
|
||
|
||
def emitted_tokens(css):
|
||
return sorted(set(re.findall(r"(--color-primary[a-z0-9-]*)\s*:", css)))
|
||
|
||
|
||
def selfcheck(css, base_light, base_dark):
|
||
reds = []
|
||
# A 覆盖完备
|
||
need = set(upstream_tokens(LIGHT_UP)) | set(upstream_tokens(DARK_UP))
|
||
have = set(emitted_tokens(css))
|
||
missing = need - have
|
||
if missing:
|
||
reds.append("A 覆盖不完备,缺令牌: %s" % sorted(missing))
|
||
|
||
# B 无蓝残留(含 hover/active 展开后的字面色)
|
||
for col in re.findall(r"#[0-9A-Fa-f]{6}", css):
|
||
r, g, b = split(col)
|
||
if b > r:
|
||
reds.append("B 蓝残留: %s" % col)
|
||
|
||
# C 门槛
|
||
checks = [
|
||
("light 按钮白字", ratio(base_light, LIGHT_CONTRAST), 4.5),
|
||
("light 链接 on 白底", ratio(base_light, "#ffffff"), 4.5),
|
||
("dark 按钮黑字", ratio(base_dark, DARK_CONTRAST), 4.5),
|
||
]
|
||
for name, got, need_r in checks:
|
||
if got < need_r:
|
||
reds.append("C %s 实测 %.2f < %.2f" % (name, got, need_r))
|
||
else:
|
||
print(" ✓ %-18s %.2f:1(门槛 %.1f)" % (name, got, need_r))
|
||
|
||
# 已登记让步:仍然要盯住下限,跌破就判红
|
||
got = ratio(base_dark, "#1e1f20")
|
||
d = DEVIATIONS["dark-link-on-body"]
|
||
if got < d["floor"]:
|
||
reds.append("C 深档链接 on 深底 %.2f 跌破已登记下限 %.1f" % (got, d["floor"]))
|
||
else:
|
||
print(" ! %-18s %.2f:1 —— 已登记让步(下限 %.1f):%s"
|
||
% ("dark 链接 on 深底", got, d["floor"], d["note"]))
|
||
return reds
|
||
|
||
|
||
def negative_control():
|
||
"""拿上游蓝当输入:B/C 必须双双判红。判不红 = 仪器是空的。"""
|
||
css = emit(UPSTREAM_BLUE, UPSTREAM_BLUE, LIGHT_CONTRAST, DARK_CONTRAST)
|
||
reds = selfcheck_silent(css)
|
||
fired_blue = any("蓝残留" in r for r in reds)
|
||
fired_contrast = any("C " in r for r in reds)
|
||
return fired_blue, fired_contrast, reds
|
||
|
||
|
||
def selfcheck_silent(css):
|
||
import contextlib
|
||
import io
|
||
buf = io.StringIO()
|
||
with contextlib.redirect_stdout(buf):
|
||
return selfcheck(css, UPSTREAM_BLUE, UPSTREAM_BLUE)
|
||
|
||
|
||
def validate_model():
|
||
"""夹具对账:用生成律从上游蓝反推它自己的色阶,与上游实测值逐通道比。
|
||
文件头那句「7/7 命中」必须是跑出来的,不是写出来的。"""
|
||
s = open(LIGHT_UP, encoding="utf-8").read()
|
||
base = re.search(r"--color-primary:\s*(#[0-9a-fA-F]{6})", s).group(1)
|
||
reds = []
|
||
for kind, fn in (("dark", ramp_down), ("light", ramp_up)):
|
||
got = fn(base)
|
||
for i, want in enumerate(got, start=1):
|
||
m = re.search(r"--color-primary-%s-%d:\s*(#[0-9a-fA-F]{6})" % (kind, i), s)
|
||
if not m:
|
||
reds.append("上游缺 --color-primary-%s-%d(口径变了)" % (kind, i))
|
||
continue
|
||
a, b = split(want), split(m.group(1))
|
||
d = max(abs(x - y) for x, y in zip(a, b))
|
||
if d > 1:
|
||
reds.append("%s-%d 生成 %s vs 上游 %s(最大偏差 %d)" % (kind, i, want, m.group(1), d))
|
||
return base, reds
|
||
|
||
|
||
def main():
|
||
base, reds = validate_model()
|
||
if reds:
|
||
print("FATAL 生成律与上游实测对不上(下面的产出不可信):")
|
||
for r in reds:
|
||
print(" ✗ %s" % r)
|
||
return 2
|
||
print("生成律夹具对账:从 %s 反推上游 14 档色阶,逐通道偏差 ≤1 ⇒ 通过\n" % base)
|
||
|
||
print("反向自证(喂上游蓝,必须判红):")
|
||
fired_blue, fired_contrast, reds = negative_control()
|
||
if not (fired_blue and fired_contrast):
|
||
print("FATAL 仪器失效:蓝残留判定=%s 对比度判定=%s" % (fired_blue, fired_contrast))
|
||
print(" 实际判红项: %s" % reds)
|
||
return 2
|
||
print(" ✓ 蓝残留被抓 %d 处、对比度不达标被抓 %d 处\n"
|
||
% (sum(1 for r in reds if "蓝残留" in r), sum(1 for r in reds if r.startswith("C "))))
|
||
|
||
css = emit(SEAL_PAPER, SEAL_DEEP, LIGHT_CONTRAST, DARK_CONTRAST)
|
||
print("正式产出自检:")
|
||
reds = selfcheck(css, SEAL_PAPER, SEAL_DEEP)
|
||
if reds:
|
||
print("\n判红:")
|
||
for r in reds:
|
||
print(" ✗ %s" % r)
|
||
return 1
|
||
|
||
os.makedirs(os.path.dirname(OUT), exist_ok=True)
|
||
with open(OUT, "w", encoding="utf-8") as f:
|
||
f.write(css)
|
||
print("\n已写出 %s(%d 字节,%d 个 primary 令牌)"
|
||
% (OUT, len(css), len(emitted_tokens(css))))
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main())
|