Files
frontend_v2/.workbuddy/memory/2026-09-15.md
toom1996 3f79cef587 update
2026-09-15 19:59:14 +08:00

34 lines
4.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 2026-09-15 工作日志
## 记住语言偏好功能 ✅(11:43–12:00)
用户要求:选过语言后,下次进首页直接用上次的语言。
- 关键前提:本项目 `prefixDefaultLocale: true`,/en、/cn 都带前缀,根 `/` 由服务端 302 到 `/en`。故「进首页」实际落在 /en,在此做自动跳转。
- `src/lib/i18n/index.ts` 新增 `STORED_LOCALE_KEY='preferred_locale'`、`storeLocale(locale)`、`getStoredLocale()`(localStorage 读写,单一来源)。
- `src/layouts/Layout.astro`:
- `<head>` 顶部加 `is:inline` + `define:vars` 脚本,进首页(path==='/' 或 '/'+defaultLocale)且记住了非默认语言时 `location.replace('/'+stored)`。脚本在 head 同步执行,先于首屏绘制,基本无闪白。
- 语言切换器 `x-data="{ open:false }"` → `langSwitch()`;`<a>` `@click` 改为 `open=false; pick('<code>')`。
- footer 脚本 import `storeLocale`,注册 `langSwitch` Alpine 组件(含 `pick(code){ storeLocale(code) }`)。
- **设计铁律**:只在「显式点击切换器」时写 localStorage,绝不按页面加载的 URL 写——否则与首页自动跳转冲突(点了英文又被 URL 上的 en 覆盖,首页永远跳不回去)。
- 验证:`npm run build` Complete;`astro check` 0/0/0;产物 HTML 确认内联脚本注入 `const defaultLocale="en"; const storedKey="preferred_locale";` 且两个 `pick('cn')`/`pick('en')` 锚点存在。
- 顺带整理了被截断的超长 MEMORY.md(重写精简版,保留架构/约定/脚本铁律/类型坑/lib分层/验证手段/门禁/账号/i18n/记住语言)。
## 语言建议弹窗(未选过语言时按浏览器语言提示)✅(12:11–12:30)
用户追加需求:没选过语言时,按浏览器语言自动判断,并弹小窗提示是否切换。
- `Layout.astro` footer `<script>`(alpine:init 内)新增 `localeSuggest` Alpine 组件,import 扩展为 `storeLocale, getStoredLocale, DEFAULT_LOCALE, LOCALE_NAMES`。
- `init()`:已 `getStoredLocale()` 则返回(交给 head 脚本重定向,不弹);否则读 `navigator.language`,`/^(zh|cmn|zho)/` → 'cn' 否则 'en';仅在首页(`p==='/' || p==='/' + def`)且 `detected !== cur` 时显示。
- `message` getter:target='cn' 时中文「检测到您的浏览器语言为「中文」,是否切换到中文界面?」;否则英文兜底。
- `switchLang()`:`storeLocale(target)` + `location.replace('/'+target)`;`keep()`:`storeLocale(current)`(记下"保持当前默认"避免再弹)+ 隐藏。
- body 末尾加弹窗标记 `x-data="localeSuggest()"` + `x-show="visible"` + `x-cloak` + `x-transition`,两个按钮 `keep()/switchLang()`,标签用 `names[target]/names[current]`(LOCALE_NAMES.nativeName:English / 中文)。
- 设计要点:弹窗与 head 重定向互斥(靠 `getStoredLocale()` 判存);点「保持」写 `current`(默认 en)即压制后续弹窗与重定向。
- 验证:`npm run build` Complete;`astro check` 0/0/0;产物 HTML 含 popup 标记、JS bundle 含 localeSuggest + 中英文案。
## 字体统一:移除 font-mono / font-serif ✅(16:16–16:23)
用户要求:font-mono 这类字体都不要了,否则字体不统一。
- 站里原混用 `font-sans`(系统栈,默认)+ `font-mono`(等宽)+ `font-serif`(衬线)三类,视觉不统一。
- 用脚本批量剥除 `src` 下全部 `font-mono`/`font-serif` 工具类(9 个 .astro 文件:Layout/LoginPage/AccountPage/AuthModal/BrandModal/ComingSoon/GalleryLightbox/RunwayLookCard/StreetSnapCard),UTF-8 无 BOM 精确回写,只删 token 不动其余。
- 两处"裸"字体声明单独手改:
- `LoadingOverlay.astro` `<style>`:删 `#loading-screen h1` 的 `ui-serif,...serif` 与 `.ls-sub` 的 `ui-monospace,...monospace` 两行 `font-family`(改继承 body 的 font-sans);同步更新注释里的"mono 小标"措辞。
- `AccountPage.astro` SVG 占位图 `<text font-family="monospace">` → `sans-serif`(SVG 作为 data URI 隔离渲染,必须显式给字体)。
- 残留核查:`font-mono|font-serif|monospace|ui-serif|ui-monospace` 在 src 下 0 命中。全站统一为 `font-sans`(系统字体栈)。
- 验证:`npm run build` Complete;`astro check` 0/0/0。