Skip to content

🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.

perf(site): 首页 HTML 减小约 150 KB,修复线上 HTML 没有压缩

dyk984a5464413654
diff --git a/site/deploy/nginx.conf b/site/deploy/nginx.conf
index a1d4607..7a39788 100644
--- a/site/deploy/nginx.conf
+++ b/site/deploy/nginx.conf
@@ -1,4 +1,4 @@
-# 官网静态文件。TLS、压缩策略、域名由宿主机的 Caddy(/etc/caddy/sites.d)负责,这里只在容器内 8080 提供文件。
+# 官网静态文件。TLS、域名由宿主机的 Caddy(/etc/caddy/sites.d)负责,这里只在容器内 8080 提供文件。
server {
listen 8080;
server_name _;
@@ -7,10 +7,11 @@ server {
server_tokens off;
charset utf-8;
- # 默认等级 1 太松:首页 HTML(大量重复的机器人眼睛 SVG)等级 1 是 49 KB,6 是 37 KB。
- # 这里压过之后 Caddy 的 encode 会原样转发,所以等级要在这里给够
+ # 默认等级 1 太松,等级要在这里给够。压缩只在这里做:Caddy 的站点配置没有 encode,只管转发。
+ # gzip_proxied 必须是 any:Caddy 转发时带 Via 头,默认的 off 会让 nginx 不压缩代理来的请求
gzip on;
gzip_comp_level 6;
+ gzip_proxied any;
gzip_min_length 256;
gzip_vary on;
gzip_types text/css application/javascript text/javascript application/json image/svg+xml application/xml text/plain application/manifest+json;
diff --git a/site/src/components/BotFace.astro b/site/src/components/BotFace.astro
index 1292fcc..5f84aef 100644
--- a/site/src/components/BotFace.astro
+++ b/site/src/components/BotFace.astro
@@ -16,12 +16,8 @@ const style = [
`--tip-x:${c.tip[0]}%`, `--tip-y:${c.tip[1]}%`,
`--bf-seed:${(seed ?? (char.charCodeAt(0) * 37 + char.length * 101) % 1000 / 1000).toFixed(3)}`,
].join(";");
-const R = c.r;
-const f = (n: number) => +(n * R).toFixed(2);
-const spiral = Array.from({ length: 29 }, (_, i) => {
- const t = (i / 28) * Math.PI * 4.2, rr = (0.12 + (0.9 * i) / 28) * R;
- return `${i ? "L" : "M"}${(Math.cos(t) * rr).toFixed(2)} ${(Math.sin(t) * rr).toFixed(2)}`;
-}).join("");
+// 只有哒哒、晶晶有发光层(styles/bots.css),别的角色不输出空节点
+const glow = char === "red" || char === "purple";
const parts = ["ear-l", "ear-r", "top"];
---
<div class:list={["bot-face", { lively, pokeable, sm: size < 36 }, cls]} style={style} data-char={char} data-state={state} data-eyes="open" aria-hidden="true" {...rest}>
@@ -30,23 +26,16 @@ const parts = ["ear-l", "ear-r", "top"];
<div class="bf-body">
<div class="bf-shot">
<div class="bf-look">
- {parts.map((k) => <i class={`bf-part bf-${k}`}><i class="bf-pin"><b class="bf-img"></b><b class="bf-glow"></b></i></i>)}
- <i class="bf-part bf-head"><b class="bf-img"></b><b class="bf-glow"></b></i>
+ {parts.map((k) => <i class={`bf-part bf-${k}`}><i class="bf-pin"><b class="bf-img"></b>{glow && <b class="bf-glow"></b>}</i></i>)}
+ <i class="bf-part bf-head"><b class="bf-img"></b>{glow && <b class="bf-glow"></b>}</i>
{c.lens && c.lens.slice(0, 2).map((l) => <i class="bf-lens" style={`left:${(l as number[])[0]}%;top:${(l as number[])[1]}%;--lens:${c.lens![2] * 2}%`}></i>)}
{c.eyes.map((e) => <i class="bf-blush" style={`left:${(e[0] + (e[0] < 50 ? -5.6 : 5.6)).toFixed(2)}%;top:${(e[1] + 6.2).toFixed(2)}%`}></i>)}
<svg class="bf-eyes" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<g class="bf-gaze"><g class="bf-glance">
{c.eyes.map((e, i) => (
<g transform={`translate(${e[0]} ${e[1]})${i ? " scale(-1 1)" : ""}`}>
- <g class="bf-lid">
- <circle class="e e-open" r={R} />
- <path class="e e-happy line" d={`M${f(-1.05)} ${f(0.45)}Q0 ${f(-1.3)} ${f(1.05)} ${f(0.45)}`} />
- <path class="e e-closed line" d={`M${f(-1.05)} ${f(-0.15)}Q0 ${f(0.8)} ${f(1.05)} ${f(-0.15)}`} />
- <path class="e e-sad" d={`M${f(-1.05)} 0L${f(1.05)} 0A${f(1.05)} ${f(1.05)} 0 0 1 ${f(-1.05)} 0Z`} />
- <path class="e e-x line" d={`M${f(-0.8)} ${f(-0.8)}L${f(0.8)} ${f(0.8)}M${f(0.8)} ${f(-0.8)}L${f(-0.8)} ${f(0.8)}`} />
- <path class="e e-spiral line thin" d={spiral} />
- <path class="e e-heart" d={`M0 ${f(1.05)}C${f(-1.7)} ${f(-0.05)} ${f(-1)} ${f(-1.4)} 0 ${f(-0.5)}C${f(1)} ${f(-1.4)} ${f(1.7)} ${f(-0.05)} 0 ${f(1.05)}Z`} />
- </g>
+ {/* 其余表情由 lib/eyes.ts 补上,原因见 lib/eye-shapes.ts */}
+ <g class="bf-lid"><circle class="e e-open" r={c.r} /></g>
</g>
))}
</g></g>
diff --git a/site/src/lib/eye-shapes.ts b/site/src/lib/eye-shapes.ts
new file mode 100644
index 0000000..0deb78d
--- /dev/null
+++ b/site/src/lib/eye-shapes.ts
@@ -0,0 +1,18 @@
+// 机器人眼睛除了睁眼以外的表情。它们平时透明,只有脚本切换 data-eyes 时才显示,
+// 而首页有近百个头像、每个两只眼,全写进 HTML 要多出约 130 KB,部分目录站的校验会嫌页面太大。
+// 所以 BotFace.astro 只输出睁眼的圆(无 JS 的静态第一帧也只用到它),其余由 lib/eyes.ts 启动时补上。
+export function eyeShapes(R: number): string {
+ const f = (n: number) => +(n * R).toFixed(2);
+ const spiral = Array.from({ length: 29 }, (_, i) => {
+ const t = (i / 28) * Math.PI * 4.2, rr = (0.12 + (0.9 * i) / 28) * R;
+ return `${i ? "L" : "M"}${(Math.cos(t) * rr).toFixed(2)} ${(Math.sin(t) * rr).toFixed(2)}`;
+ }).join("");
+ return [
+ ["e e-happy line", `M${f(-1.05)} ${f(0.45)}Q0 ${f(-1.3)} ${f(1.05)} ${f(0.45)}`],
+ ["e e-closed line", `M${f(-1.05)} ${f(-0.15)}Q0 ${f(0.8)} ${f(1.05)} ${f(-0.15)}`],
+ ["e e-sad", `M${f(-1.05)} 0L${f(1.05)} 0A${f(1.05)} ${f(1.05)} 0 0 1 ${f(-1.05)} 0Z`],
+ ["e e-x line", `M${f(-0.8)} ${f(-0.8)}L${f(0.8)} ${f(0.8)}M${f(0.8)} ${f(-0.8)}L${f(-0.8)} ${f(0.8)}`],
+ ["e e-spiral line thin", spiral],
+ ["e e-heart", `M0 ${f(1.05)}C${f(-1.7)} ${f(-0.05)} ${f(-1)} ${f(-1.4)} 0 ${f(-0.5)}C${f(1)} ${f(-1.4)} ${f(1.7)} ${f(-0.05)} 0 ${f(1.05)}Z`],
+ ].map(([cls, d]) => `<path class="${cls}" d="${d}"></path>`).join("");
+}
diff --git a/site/src/lib/eyes.ts b/site/src/lib/eyes.ts
index 36a7281..02b8977 100644
--- a/site/src/lib/eyes.ts
+++ b/site/src/lib/eyes.ts
@@ -1,5 +1,6 @@
// Eyes 标记与毛绒机器人的"看"(§7.7、§7.9)。一个全局 pointermove + rAF 合并;IntersectionObserver 管可见性;
// 先统一读 getBoundingClientRect,再统一写 --look-x/--look-y。无依赖。
+import { eyeShapes } from "./eye-shapes";
const clamp = (v: number, a: number, b: number) => Math.min(b, Math.max(a, v));
const rnd = (a: number, b: number) => a + Math.random() * (b - a);
@@ -318,3 +319,9 @@ export function mountEyes(root: ParentNode = document) {
reduce.addEventListener("change", () => location.reload());
}
}
+
+// HTML 里每只眼睛只有睁眼的圆,这里补上其余表情(原因见 lib/eye-shapes.ts)。切换 data-eyes 的代码都在这个模块里,所以放在模块加载时做
+document.querySelectorAll(".bf-lid").forEach((lid) => {
+ const r = Number(lid.querySelector("circle")?.getAttribute("r"));
+ if (r) lid.insertAdjacentHTML("beforeend", eyeShapes(r));
+});
diff --git a/site/src/sections/Devices.astro b/site/src/sections/Devices.astro
index d06181b..a0a4f3c 100644
--- a/site/src/sections/Devices.astro
+++ b/site/src/sections/Devices.astro
@@ -171,7 +171,7 @@ for (let y = 0; y < 29; y++) for (let x = 0; x < 29; x++) {
{c.guide.limit && <p class="small muted">{c.guide.limit}</p>}
{c.guide.qr && (
<figure class="qr-sample"><svg viewBox="0 0 29 29" width="96" height="96" aria-hidden="true">
- {qr.map(([x, y]) => <rect x={x} y={y} width="1" height="1" />)}
+ <path d={qr.map(([x, y]) => `M${x} ${y}h1v1h-1z`).join("")} />
</svg><figcaption class="small muted">{c.guide.qr}</figcaption></figure>
)}
</section>