From 3a226ffe53d92db411cbfed16147a4d6bd3f34bd Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 11 Oct 2026 01:34:29 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=86=E7=AB=99=E7=82=B9=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E9=87=8D=E5=86=99=E4=B8=BA=20Material=20Design=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 daisyUI,改用 Tailwind v4 + 自建 M3 设计令牌(色彩角色、字阶、 形状、阴影层级、缓动),颜色用 light-dark() 一次声明亮/暗两套 - 手写 M3 组件:顶栏(含服务端渲染的面包屑)、Filled/Tonal/Outlined 按钮、图标按钮、卡片、Filter chip、列表项、搜索栏与搜索视图 - 搜索改为手机全屏、桌面悬浮的 M3 搜索视图,新增清除按钮与点击遮罩关闭 - 主题切换改为顶栏图标开关并带 aria-pressed - 代码块改用 Shiki 亮/暗双主题,跟随页面主题 - Waline 评论区按 M3 角色换肤 - 自托管 Roboto / Roboto Mono 字体 - 更新 README,调整并补充 Playwright 测试 Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Kp1FWSg2KNQv7CgwopXfVs --- README.md | 36 ++- astro.config.mjs | 7 +- package-lock.json | 132 ++-------- package.json | 3 +- src/assets/Comments.css | 67 ++++-- src/assets/NavBar.css | 112 +++++++-- src/assets/PostList.css | 55 ++++- src/assets/SearchModal.css | 129 +++++++++- src/assets/app.css | 239 +------------------ src/assets/base.css | 57 +++++ src/assets/components.css | 344 +++++++++++++++++++++++++++ src/assets/index.css | 27 ++- src/assets/prose.css | 195 +++++++++++++++ src/assets/tokens.css | 140 +++++++++++ src/components/Card.astro | 13 +- src/components/Comments.astro | 2 +- src/components/NavBar.astro | 103 ++++---- src/components/Placeholder.astro | 3 - src/components/PostCard.astro | 20 +- src/components/SearchModal.astro | 135 +++++++---- src/components/ThemeController.astro | 63 +++-- src/layouts/BaseLayout.astro | 31 ++- src/layouts/PostsLayout.astro | 30 ++- src/pages/index.astro | 46 ++-- src/pages/posts/index.astro | 27 ++- src/pages/posts/tags.astro | 42 ++-- src/pages/posts/topic.astro | 42 ++-- src/scripts/postFilter.ts | 8 +- tests/site.spec.ts | 56 ++++- 29 files changed, 1483 insertions(+), 681 deletions(-) create mode 100644 src/assets/base.css create mode 100644 src/assets/components.css create mode 100644 src/assets/prose.css create mode 100644 src/assets/tokens.css delete mode 100644 src/components/Placeholder.astro diff --git a/README.md b/README.md index dd9225c..61e6487 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # blog-rewrite -一个基于 [Astro](https://astro.build/) + [Tailwind CSS v4](https://tailwindcss.com/) + [daisyUI](https://daisyui.com/) 的个人博客项目。 +一个基于 [Astro](https://astro.build/) + [Tailwind CSS v4](https://tailwindcss.com/) 的个人博客项目,界面遵循 [Material Design 3](https://m3.material.io/) 规范。 ## 特性 @@ -8,14 +8,15 @@ - 自动生成文章列表与文章页 - 支持标签、专题、日期排序 - 内置代码高亮与 KaTeX 数学公式 -- 使用 daisyUI 主题,并支持本地 `localStorage` 记忆 +- Material Design 3 设计令牌(色彩角色、字阶、形状、层级与动效),支持浅色 / 深色主题并记忆选择 +- 顶栏、按钮、卡片、筛选芯片、搜索视图等组件均按 M3 规范实现 - 带有评论组件接入位 ## 技术栈 - Astro 7 - Tailwind CSS v4 -- daisyUI 5 +- Roboto(`@fontsource-variable`,自托管) - remark-breaks - astro-icon - Waline @@ -63,7 +64,7 @@ npm run verify ```text src/ - assets/ 全局样式与组件样式 + assets/ 设计令牌(tokens.css)、基础样式与各组件样式 components/ 可复用组件 layouts/ 页面布局 pages/ 路由页面与文章内容 @@ -79,13 +80,36 @@ public/ 静态资源 - `src/pages/posts/topic.astro`:专题页 - `src/pages/posts/tags.astro`:标签页 +## 设计系统 + +样式不依赖 UI 组件库,由 `src/assets/` 下的几个文件组成,全部在 `app.css` 中汇总: + +| 文件 | 内容 | +| --- | --- | +| `tokens.css` | `@theme` 中的 M3 令牌:色彩角色、字阶、形状、阴影层级、缓动曲线 | +| `base.css` | 配色方案、焦点环、`prefers-reduced-motion` 降级 | +| `components.css` | 状态层、按钮、图标按钮、卡片、芯片、列表项、搜索栏 | +| `NavBar.css` | 顶栏与面包屑 | +| `SearchModal.css` | 搜索视图(手机全屏,桌面悬浮对话框) | +| `PostList.css` / `index.css` | 文章卡片网格 / 首页 | +| `prose.css` | Markdown 正文与代码块 | +| `Comments.css` | Waline 评论区配色(不进入 cascade layer,才能覆盖 Waline 自带样式) | + +要点: + +- 每个颜色角色只写一次:`--color-primary: light-dark(#6750A4, #CFBCFF)`,由 `color-scheme` 决定取亮色还是暗色值。 +- 色板由种子色 `#6750A4` 经 `@material/material-color-utilities` 生成;换主题色只需替换 `tokens.css` 里的十六进制值。 +- 令牌同时是 Tailwind 工具类:`bg-surface-container`、`text-on-surface-variant`、`text-title-large`、`rounded-lg`(= M3 的 large 圆角,16px)、`shadow-elevation-2` 等。已移除 Tailwind 默认的颜色、字号、圆角和阴影,请只使用 M3 令牌。 +- 组件类以 `m3-` 为前缀,如 `m3-button m3-button--tonal`、`m3-card m3-card--outlined`、`m3-chip`。 +- 代码块使用 Shiki 的 `github-light-high-contrast` / `github-dark-high-contrast` 双主题,随页面主题切换。 + ## 主题切换 -项目内置了主题切换组件 `src/components/ThemeController.astro`。 +主题切换组件是 `src/components/ThemeController.astro`(顶栏右侧的图标按钮)。 - 首次进入会优先跟随系统浅色/深色偏好 - 用户手动切换后会写入 `localStorage` -- 刷新页面后会自动恢复上次主题 +- 刷新页面后会自动恢复上次主题(`Head.astro` 中的内联脚本会在首次绘制前设置 `data-theme`,避免闪烁) ## 说明 diff --git a/astro.config.mjs b/astro.config.mjs index be7e4bb..41e49bd 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -65,7 +65,12 @@ export default defineConfig({ }, markdown: { shikiConfig: { - theme: 'github-dark-high-contrast', + // Both themes are emitted as CSS variables; prose.css picks one from the active colour scheme. + themes: { + light: 'github-light-high-contrast', + dark: 'github-dark-high-contrast', + }, + defaultColor: false, }, processor: unified({ remarkPlugins: [remarkBreaks, autoPostsLayout], diff --git a/package-lock.json b/package-lock.json index 0d53eea..9b5872e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,8 @@ "@astrojs/markdown-remark": "^7.3.2", "@astrojs/rss": "^4.0.19", "@astrojs/sitemap": "^3.7.4", + "@fontsource-variable/roboto": "^5.3.0", + "@fontsource-variable/roboto-mono": "^5.3.0", "@iconify-json/material-symbols": "^1.2.83", "@iconify-json/mdi": "^1.2.3", "@iconify-json/mingcute": "^1.2.7", @@ -18,7 +20,6 @@ "@waline/client": "^3.16.0", "astro": "^7.3.6", "astro-icon": "^1.2.0", - "daisyui": "^5.6.7", "katex": "^0.19.0", "remark-breaks": "^4.0.0", "tailwindcss": "^4.3.2" @@ -206,9 +207,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -225,9 +223,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -244,9 +239,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -263,9 +255,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -586,9 +575,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -602,9 +588,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -618,9 +601,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -634,9 +614,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -1276,6 +1253,24 @@ "node": ">=18" } }, + "node_modules/@fontsource-variable/roboto": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/roboto/-/roboto-5.3.0.tgz", + "integrity": "sha512-BoaaZiQf8fgtxv07KXkTwx1bKz/EoqIlTXq2OOKKXINxp6qXWdnlChqV+hSaDANS49yyUASFl3OVBMMDTCIHFA==", + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource-variable/roboto-mono": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource-variable/roboto-mono/-/roboto-mono-5.3.0.tgz", + "integrity": "sha512-h5r+KY/6qy8JEOj33JgcrFO81YAnvrc1EAwMpl/EPJLb2OIvOy0/jmB5M7qs7x/uXk5JUP5Ux4LrkeOK7faHkQ==", + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, "node_modules/@iconify-json/material-symbols": { "version": "1.2.83", "resolved": "https://registry.npmjs.org/@iconify-json/material-symbols/-/material-symbols-1.2.83.tgz", @@ -1447,9 +1442,6 @@ "cpu": [ "arm" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1466,9 +1458,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1485,9 +1474,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1504,9 +1490,6 @@ "cpu": [ "riscv64" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1523,9 +1506,6 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1542,9 +1522,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1561,9 +1538,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1580,9 +1554,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "LGPL-3.0-or-later", "optional": true, "os": [ @@ -1599,9 +1570,6 @@ "cpu": [ "arm" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1624,9 +1592,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1649,9 +1614,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1674,9 +1636,6 @@ "cpu": [ "riscv64" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1699,9 +1658,6 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1724,9 +1680,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1749,9 +1702,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -1774,9 +1724,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "Apache-2.0", "optional": true, "os": [ @@ -2133,9 +2080,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2152,9 +2096,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -2171,9 +2112,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2190,9 +2128,6 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2209,9 +2144,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -2228,9 +2160,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3647,15 +3576,6 @@ "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", "license": "MIT" }, - "node_modules/daisyui": { - "version": "5.6.7", - "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-5.6.7.tgz", - "integrity": "sha512-FVpuUbesyAUBWNp5pXn9JDF1EWt3IZJzp5Staw1YqfP0MwL36sv3wtmfWeuEBkZcazaQbeZXA91oW5dSB+TUEg==", - "license": "MIT", - "funding": { - "url": "https://github.com/saadeghi/daisyui?sponsor=1" - } - }, "node_modules/debug": { "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", @@ -7869,9 +7789,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -7892,9 +7809,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -7915,9 +7829,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -7938,9 +7849,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ diff --git a/package.json b/package.json index ca75c88..88a3e6b 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "@astrojs/markdown-remark": "^7.3.2", "@astrojs/rss": "^4.0.19", "@astrojs/sitemap": "^3.7.4", + "@fontsource-variable/roboto": "^5.3.0", + "@fontsource-variable/roboto-mono": "^5.3.0", "@iconify-json/material-symbols": "^1.2.83", "@iconify-json/mdi": "^1.2.3", "@iconify-json/mingcute": "^1.2.7", @@ -25,7 +27,6 @@ "@waline/client": "^3.16.0", "astro": "^7.3.6", "astro-icon": "^1.2.0", - "daisyui": "^5.6.7", "katex": "^0.19.0", "remark-breaks": "^4.0.0", "tailwindcss": "^4.3.2" diff --git a/src/assets/Comments.css b/src/assets/Comments.css index c738187..9708195 100644 --- a/src/assets/Comments.css +++ b/src/assets/Comments.css @@ -1,16 +1,55 @@ +/* + * Waline ships unlayered CSS, so this file is deliberately not part of the app.css + * cascade layers: the #waline selectors below have to out-rank its rules. + */ #waline { - --waline-white: var(--color-base-100); - --waline-theme-color: var(--color-base-content); - --waline-active-color: var(--color-base-content); - --waline-border: 1px solid color-mix(in oklab, var(--color-base-content) 20%, transparent); - --waline-bg-color: var(--color-base-200); - --waline-bg-color-light: var(--color-base-300); - --waline-bg-color-hover: var(--color-base-300); - --waline-border-color: color-mix(in oklab, var(--color-base-content) 20%, transparent); - --waline-color: var(--color-base-content); - --waline-info-color: color-mix(in oklab, var(--color-base-content) 78%, var(--color-base-200)); - --waline-light-grey: color-mix(in oklab, var(--color-base-content) 72%, var(--color-base-200)); - --waline-dark-grey: color-mix(in oklab, var(--color-base-content) 88%, var(--color-base-200)); - --waline-disable-bg-color: var(--color-base-300); - --waline-disable-color: color-mix(in oklab, var(--color-base-content) 70%, var(--color-base-300)); + --waline-white: var(--color-on-primary); + --waline-theme-color: var(--color-primary); + --waline-active-color: color-mix(in oklab, var(--color-primary) 80%, var(--color-on-surface)); + --waline-color: var(--color-on-surface); + --waline-bg-color: var(--color-surface); + --waline-bg-color-light: var(--color-surface-container); + --waline-bg-color-hover: var(--color-surface-container-high); + --waline-border-color: var(--color-outline-variant); + --waline-border: 1px solid var(--color-outline-variant); + --waline-disable-bg-color: var(--color-surface-container-high); + --waline-disable-color: var(--color-on-surface-variant); + --waline-bq-color: var(--color-surface-container-highest); + --waline-info-bg-color: var(--color-surface-container-high); + --waline-info-color: var(--color-on-surface-variant); + --waline-light-grey: var(--color-on-surface-variant); + --waline-dark-grey: var(--color-on-surface-variant); + --waline-badge-color: var(--color-tertiary); + font-family: var(--font-sans); +} + +#waline .wl-panel { + border-radius: var(--radius-md); +} + +#waline .wl-btn { + padding: 0.5em 1.5em; + border-color: var(--color-outline); + border-radius: 9999px; + font-weight: 500; +} + +#waline .wl-btn:not(.primary, :disabled):hover, +#waline .wl-btn:not(.primary, :disabled):active { + background-color: color-mix(in oklab, var(--color-primary) 8%, transparent); +} + +#waline .wl-btn.primary { + border-color: transparent; +} + +#waline .wl-btn.primary:hover, +#waline .wl-btn.primary:active { + border-color: transparent; + box-shadow: var(--shadow-elevation-1); +} + +#waline .wl-btn:disabled { + border-color: transparent; + box-shadow: none; } diff --git a/src/assets/NavBar.css b/src/assets/NavBar.css index ecf7547..4534caa 100644 --- a/src/assets/NavBar.css +++ b/src/assets/NavBar.css @@ -1,26 +1,108 @@ -.breadcrumb { - display: block; - max-width: calc(100vw - 6.5rem); +/* Top app bar: sits on the surface and shifts to surface-container once the page scrolls. */ +.m3-top-app-bar { + position: sticky; + inset-block-start: 0; + z-index: 40; + background-color: var(--color-surface); + transition: background-color 200ms var(--ease-standard); } -.breadcrumb .link { - color: var(--color-base-content); - text-decoration: none; +.m3-top-app-bar[data-scrolled] { + background-color: var(--color-surface-container); +} + +.m3-top-app-bar__inner { + display: flex; + align-items: center; + gap: 0.5rem; + max-width: 64rem; + min-height: var(--top-app-bar-height); + margin-inline: auto; + padding-inline: 0.5rem; +} + +@media (min-width: 40rem) { + .m3-top-app-bar__inner { + padding-inline: 1rem; + } } -.breadcrumb .link:hover { - text-decoration: underline; +/* Breadcrumb: M3 has no breadcrumb, so it is built from the app bar's title and icon-button parts. */ +.m3-breadcrumb { + flex: 1; + min-width: 0; } -.breadcrumb .breadcrumbs { +.m3-breadcrumb__list { + display: flex; + align-items: center; + margin: 0; + padding: 0; overflow-x: auto; + list-style: none; + scrollbar-width: none; white-space: nowrap; - max-width: 100%; - -webkit-overflow-scrolling: touch; } -@media (min-width: 640px) { - .breadcrumb { - max-width: calc(100vw - 2rem); - } +.m3-breadcrumb__list::-webkit-scrollbar { + display: none; +} + +.m3-breadcrumb__list > li { + display: flex; + flex: none; + align-items: center; +} + +/* The list scrolls, so keep the ring inside the link instead of letting it be clipped. */ +.m3-breadcrumb :focus-visible { + outline-offset: -3px; +} + +.m3-breadcrumb__sep { + flex: none; + width: 1.25rem; + height: 1.25rem; + color: var(--color-outline); +} + +.m3-breadcrumb__link { + display: inline-flex; + align-items: center; + min-height: 2.5rem; + padding-inline: 0.75rem; + border-radius: 9999px; + color: var(--color-on-surface-variant); + text-decoration: none; + @apply text-title-small; +} + +.m3-breadcrumb__current { + display: inline-flex; + align-items: center; + gap: 0.5rem; + min-height: 2.5rem; + padding-inline: 0.75rem; + color: var(--color-on-surface); + @apply text-title-medium; +} + +.m3-breadcrumb__current > svg { + flex: none; + width: 1.5rem; + height: 1.5rem; + color: var(--color-primary); +} + +/* Theme toggle shows the icon of the current theme. */ +.m3-theme-icon--dark { + display: none; +} + +:root[data-theme="dark"] .m3-theme-icon--light { + display: none; +} + +:root[data-theme="dark"] .m3-theme-icon--dark { + display: block; } diff --git a/src/assets/PostList.css b/src/assets/PostList.css index c8a3229..fbda475 100644 --- a/src/assets/PostList.css +++ b/src/assets/PostList.css @@ -1,18 +1,49 @@ -.post { - color: var(--color-base-content); - text-decoration: none; +.m3-post-grid { + display: grid; + grid-template-columns: minmax(0, 1fr); + gap: 1rem; } -.list-btn:hover { - border-color: var(--color-base-content); - cursor: pointer; +@media (min-width: 40rem) { + .m3-post-grid { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } } -.list-btn-active { - color: var(--color-base-100); - background-color: var(--color-base-content); +@media (min-width: 64rem) { + .m3-post-grid { + grid-template-columns: repeat(3, minmax(0, 1fr)); + } } -.list-post:hover { - border-color: var(--color-base-content); -} \ No newline at end of file +.m3-post-card { + gap: 0.5rem; + padding: 1rem 1.25rem 1.25rem; +} + +.m3-post-card__meta { + color: var(--color-on-surface-variant); + @apply text-label-medium; +} + +.m3-post-card__title { + color: var(--color-on-surface); + @apply text-title-large; +} + +.m3-post-card__description { + display: -webkit-box; + overflow: hidden; + -webkit-box-orient: vertical; + -webkit-line-clamp: 3; + line-clamp: 3; + color: var(--color-on-surface-variant); + @apply text-body-medium; +} + +.m3-post-card__tags { + display: flex; + flex-wrap: wrap; + gap: 0.5rem; + margin-top: 0.25rem; +} diff --git a/src/assets/SearchModal.css b/src/assets/SearchModal.css index 31789c1..22ad74d 100644 --- a/src/assets/SearchModal.css +++ b/src/assets/SearchModal.css @@ -1,13 +1,126 @@ -.modal { - border: 0 !important; +/* + * Search view: full screen on compact windows, a docked dialog from 640px up. + * Open/close animates with @starting-style, which also covers the top layer. + */ +.m3-search-view { + position: fixed; + inset: 0; + width: 100%; + max-width: none; + height: 100dvh; + max-height: none; + margin: 0; + padding: 0; + overflow: hidden; + border: 0; + border-radius: 0; + background-color: var(--color-surface-container-high); + color: var(--color-on-surface); + opacity: 0; + transform: translateY(-1rem); + transition: + opacity 200ms var(--ease-standard), + transform 300ms var(--ease-emphasized-decelerate), + overlay 300ms allow-discrete, + display 300ms allow-discrete; } -#search_input { - border: 1px solid var(--color-base-content); - background-color: var(--color-base-300); +.m3-search-view[open] { + display: flex; + flex-direction: column; + opacity: 1; + transform: none; } -#search_input:focus-visible { - outline: 2px solid var(--color-info); - outline-offset: 2px; +@starting-style { + .m3-search-view[open] { + opacity: 0; + transform: translateY(-1rem); + } +} + +.m3-search-view::backdrop { + background-color: rgb(0 0 0 / 0.32); + opacity: 0; + transition: + opacity 300ms var(--ease-standard), + overlay 300ms allow-discrete, + display 300ms allow-discrete; +} + +.m3-search-view[open]::backdrop { + opacity: 1; +} + +@starting-style { + .m3-search-view[open]::backdrop { + opacity: 0; + } +} + +@media (min-width: 40rem) { + .m3-search-view { + inset: 4rem 0 auto; + width: min(45rem, calc(100% - 3rem)); + height: min(40rem, calc(100dvh - 8rem)); + margin-inline: auto; + border-radius: var(--radius-xl); + box-shadow: var(--shadow-elevation-3); + } +} + +.m3-search-view__header { + display: flex; + flex: none; + align-items: center; + gap: 0.25rem; + min-height: 4.5rem; + padding-inline: 0.75rem; +} + +.m3-search-view__input { + flex: 1; + min-width: 0; + height: 3.5rem; + padding-inline: 0.5rem; + border: 0; + background-color: transparent; + color: var(--color-on-surface); + appearance: none; + @apply text-body-large; +} + +/* The caret marks the focus; the whole view is the field. */ +.m3-search-view__input:focus-visible { + outline: none; +} + +.m3-search-view__input::placeholder { + color: var(--color-on-surface-variant); + opacity: 1; +} + +.m3-search-view__input::-webkit-search-cancel-button, +.m3-search-view__input::-webkit-search-decoration { + display: none; +} + +.m3-search-view__results { + flex: 1; + min-height: 0; + padding-block: 0.5rem; + overflow-y: auto; + border-block-start: 1px solid var(--color-outline-variant); + overscroll-behavior: contain; +} + +.m3-search-view__message { + padding: 3rem 1rem; + color: var(--color-on-surface-variant); + text-align: center; + @apply text-body-medium; +} + +.m3-search-view__message--error { + color: var(--color-error); } diff --git a/src/assets/app.css b/src/assets/app.css index 90b05ef..0e68378 100644 --- a/src/assets/app.css +++ b/src/assets/app.css @@ -1,234 +1,13 @@ @import "tailwindcss"; -@plugin "daisyui" { - themes: dark --default, light --preferslight; -}; -html { - scroll-behavior: smooth; -} +/* Design tokens (an @theme block cannot live inside a layer). */ +@import "./tokens.css"; -body { - margin: 0; - min-height: 100vh; - overflow-x: hidden; -} +@import "./base.css" layer(base); -main { - width: 100%; -} - -/* Card related */ -.card-body { - border-radius: 20px; - background-color: var(--color-base-200); - gap: 1rem; -} - -.card { - border-radius: 20px; -} - -/* Typography */ -.post-date { - font-style: italic; - font-size: small; -} - -h1 { - font-size: clamp(1.75rem, 4vw, 2.5rem); - font-weight: bold; -} - -h2 { - font-size: clamp(1.4rem, 3vw, 2rem); - font-weight: bold; -} - -h3 { - font-size: clamp(1.2rem, 2.4vw, 1.5rem); - font-weight: bold; -} - -h4 { - font-size: clamp(1.1rem, 2vw, 1.25rem); - font-weight: bold; -} - -h5 { - font-size: 1rem; - font-weight: bold; -} - -p { - font-size: 1rem; - line-height: 1.75; -} - -.post-content { - width: 100%; - max-width: 100%; - line-height: 1.75; - overflow-wrap: anywhere; -} - -.post-content > * + * { - margin-top: 1rem; -} - -.post-content > :is(h2, h3, h4) { - margin-top: 2rem; - margin-bottom: 0.75rem; -} - -.post-content > br { - display: none; -} - -.post-content > :first-child { - margin-top: 0; -} - -.post-content > :last-child { - margin-bottom: 0; -} - -.post-content :is(ul, ol) { - padding-inline-start: 1.5rem; -} - -.post-content ul { - list-style: disc; -} - -.post-content ol { - list-style: decimal; -} - -.post-content li + li, -.post-content li > :is(ul, ol) { - margin-top: 0.4rem; -} - -.post-content .contains-task-list { - list-style: none; - padding-inline-start: 0; -} - -.post-content .task-list-item { - display: flex; - gap: 0.5rem; - align-items: flex-start; -} - -.post-content .task-list-item > input { - flex: none; - margin-top: 0.45rem; -} - -.post-content blockquote { - padding: 0.75rem 1rem; - border-inline-start: 0.25rem solid var(--color-info); - border-radius: 0.5rem; - background: var(--color-base-300); -} - -.post-content hr { - margin-block: 2rem; - border-color: color-mix(in oklab, var(--color-base-content) 20%, transparent); -} - -.post-content img, -.post-content iframe, -.post-content table, -.post-content pre { - width: 100%; -} - -.post-content table { - display: block; - overflow-x: auto; - border-collapse: collapse; -} - -.post-content :is(th, td) { - padding: 0.6rem 0.75rem; - border: 1px solid color-mix(in oklab, var(--color-base-content) 20%, transparent); - text-align: start; -} - -.post-content th { - background: var(--color-base-300); -} - -.post-content .katex-display { - max-width: 100%; - overflow-x: auto; - padding-block: 0.25rem; -} - -.post-content .katex-display:focus-visible { - outline: 2px solid var(--color-base-content); - outline-offset: 2px; -} - -img, -video, -table { - max-width: 100%; -} - -pre { - overflow-x: auto; -} - -/* Link style: only article body, so nav/buttons/cards stay unstyled */ -.post-content a { - color: var(--color-base-content); - text-decoration: underline; - text-decoration-thickness: 0.1em; - text-underline-offset: 0.2em; -} - -/* Code block style */ -.astro-code { - border-radius: 7px; - padding: 0.75rem 0.9rem; - overflow-x: auto; -} - -code { - border-radius: 7px; -} - -.post-content :not(pre) > code { - margin-inline: 0.2rem; - padding-inline: 0.35rem; - background-color: var(--color-base-300); - color: var(--color-base-content); - word-break: break-word; -} - -/* Self Custom */ -.center { - justify-items: center; - align-items: center; - text-align: center; - margin-inline: auto; -} - - -/* Button related */ -.btn { - box-shadow: none; - text-shadow: none; - padding: 0; - border-radius: 5rem; - min-width: 10rem; -} - -.btn-outline:hover { - border-color: var(--color-base-100); - background-color: var(--btn-color, var(--color-base-content)); - color: var(--color-base-100); - cursor: pointer; -} \ No newline at end of file +@import "./components.css" layer(components); +@import "./NavBar.css" layer(components); +@import "./PostList.css" layer(components); +@import "./SearchModal.css" layer(components); +@import "./index.css" layer(components); +@import "./prose.css" layer(components); diff --git a/src/assets/base.css b/src/assets/base.css new file mode 100644 index 0000000..8a5dae5 --- /dev/null +++ b/src/assets/base.css @@ -0,0 +1,57 @@ +:root { + /* No saved choice and no JS: follow the OS. The head script sets data-theme before first paint. */ + color-scheme: light dark; + accent-color: var(--color-primary); + --top-app-bar-height: 4rem; +} + +:root[data-theme="light"] { + color-scheme: light; +} + +:root[data-theme="dark"] { + color-scheme: dark; +} + +html { + background-color: var(--color-surface); + scroll-behavior: smooth; + scroll-padding-top: calc(var(--top-app-bar-height) + 1rem); + -webkit-text-size-adjust: 100%; + text-size-adjust: 100%; +} + +body { + min-height: 100dvh; + background-color: var(--color-surface); + color: var(--color-on-surface); + font-family: var(--font-sans); + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + @apply text-body-large; +} + +/* The skip link focuses
; it is a target, not a control, so it gets no ring. */ +main:focus { + outline: none; +} + +/* M3 focus indicator: 3dp secondary ring, 2dp away from the component. */ +:focus-visible { + outline: 3px solid var(--color-secondary); + outline-offset: 2px; +} + +@media (prefers-reduced-motion: reduce) { + html { + scroll-behavior: auto; + } + + *, + ::before, + ::after { + animation-duration: 0.01ms !important; + animation-iteration-count: 1 !important; + transition-duration: 0.01ms !important; + } +} diff --git a/src/assets/components.css b/src/assets/components.css new file mode 100644 index 0000000..2bc06dd --- /dev/null +++ b/src/assets/components.css @@ -0,0 +1,344 @@ +/* + * Shared Material Design 3 components. + * Interactive surfaces share one "state layer": an overlay in the content colour + * whose opacity is 8% on hover, 10% on focus and 10% when pressed. + */ + +:is( + .m3-button, + .m3-icon-button, + .m3-chip, + .m3-card--interactive, + .m3-list-item, + .m3-search-bar, + .m3-breadcrumb__link +) { + position: relative; + isolation: isolate; + -webkit-tap-highlight-color: transparent; +} + +:is( + .m3-button, + .m3-icon-button, + .m3-chip, + .m3-card--interactive, + .m3-list-item, + .m3-search-bar, + .m3-breadcrumb__link +)::before { + content: ""; + position: absolute; + inset: 0; + z-index: -1; + border-radius: inherit; + background-color: currentColor; + opacity: 0; + pointer-events: none; + transition: opacity 150ms var(--ease-standard); +} + +:is( + .m3-button, + .m3-icon-button, + .m3-chip, + .m3-card--interactive, + .m3-list-item, + .m3-search-bar, + .m3-breadcrumb__link +):focus-visible::before, +:is( + .m3-button, + .m3-icon-button, + .m3-chip, + .m3-card--interactive, + .m3-list-item, + .m3-search-bar, + .m3-breadcrumb__link +):active::before { + opacity: 0.1; +} + +@media (hover: hover) { + :is( + .m3-button, + .m3-icon-button, + .m3-chip, + .m3-card--interactive, + .m3-list-item, + .m3-search-bar, + .m3-breadcrumb__link + ):hover::before { + opacity: 0.08; + } +} + +/* Buttons ---------------------------------------------------------------- */ + +.m3-button { + --button-container: transparent; + --button-label: var(--color-primary); + --button-outline: transparent; + + display: inline-flex; + align-items: center; + justify-content: center; + gap: 0.5rem; + min-height: 2.5rem; + padding-inline: 1.5rem; + border: 1px solid var(--button-outline); + border-radius: 9999px; + background-color: var(--button-container); + color: var(--button-label); + cursor: pointer; + text-align: center; + text-decoration: none; + user-select: none; + transition: + box-shadow 200ms var(--ease-standard), + background-color 200ms var(--ease-standard); + @apply text-label-large; +} + +.m3-button:has(> svg:first-child) { + padding-inline-start: 1rem; +} + +.m3-button > svg { + flex: none; + width: 1.125rem; + height: 1.125rem; +} + +.m3-button--filled { + --button-container: var(--color-primary); + --button-label: var(--color-on-primary); +} + +.m3-button--tonal { + --button-container: var(--color-secondary-container); + --button-label: var(--color-on-secondary-container); +} + +.m3-button--outlined { + --button-outline: var(--color-outline); +} + +.m3-button--filled:hover, +.m3-button--tonal:hover { + box-shadow: var(--shadow-elevation-1); +} + +.m3-icon-button { + display: inline-flex; + align-items: center; + justify-content: center; + flex: none; + width: 2.5rem; + height: 2.5rem; + border-radius: 9999px; + color: var(--color-on-surface-variant); + cursor: pointer; + text-decoration: none; +} + +.m3-icon-button > svg { + width: 1.5rem; + height: 1.5rem; +} + +/* Cards ------------------------------------------------------------------ */ + +.m3-card { + display: flex; + flex-direction: column; + gap: 0.75rem; + min-width: 0; + border-radius: var(--radius-md); + color: var(--color-on-surface); + text-decoration: none; + transition: + box-shadow 200ms var(--ease-standard), + border-color 200ms var(--ease-standard); +} + +.m3-card--elevated { + background-color: var(--color-surface-container-low); + box-shadow: var(--shadow-elevation-1); +} + +.m3-card--filled { + background-color: var(--color-surface-container-highest); +} + +.m3-card--outlined { + border: 1px solid var(--color-outline-variant); + background-color: var(--color-surface); +} + +.m3-card--interactive { + cursor: pointer; +} + +.m3-card--elevated.m3-card--interactive:hover { + box-shadow: var(--shadow-elevation-2); +} + +.m3-card--outlined.m3-card--interactive:hover { + border-color: var(--color-outline); +} + +/* Page-level sections: roomier padding and the extra-large corner. */ +.m3-card--section { + gap: 1.5rem; + padding: 1.5rem; + border-radius: var(--radius-xl); +} + +@media (min-width: 40rem) { + .m3-card--section { + padding: 2rem; + } +} + +/* Chips ------------------------------------------------------------------ */ + +.m3-chip { + display: inline-flex; + align-items: center; + gap: 0.5rem; + min-height: 2rem; + padding-inline: 1rem; + border: 1px solid var(--color-outline); + border-radius: var(--radius-sm); + background-color: transparent; + color: var(--color-on-surface-variant); + cursor: pointer; + user-select: none; + transition: + background-color 200ms var(--ease-standard), + border-color 200ms var(--ease-standard); + @apply text-label-large; +} + +.m3-chip__icon { + display: none; + flex: none; + width: 1.125rem; + height: 1.125rem; +} + +/* Filter chip: the selected state shows a check and the secondary container. */ +.m3-chip[aria-pressed="true"] { + padding-inline-start: 0.5rem; + border-color: transparent; + background-color: var(--color-secondary-container); + color: var(--color-on-secondary-container); +} + +.m3-chip[aria-pressed="true"] .m3-chip__icon { + display: block; +} + +/* Tags inside a post card are labels, not controls. */ +.m3-chip--static { + min-height: 1.5rem; + padding-inline: 0.5rem; + border-color: var(--color-outline-variant); + cursor: inherit; + @apply text-label-medium; +} + +.m3-chip--static::before { + content: none; +} + +/* Lists ------------------------------------------------------------------ */ + +.m3-list-item { + display: flex; + align-items: flex-start; + gap: 1rem; + padding: 0.75rem 1rem; + color: var(--color-on-surface); + text-decoration: none; +} + +.m3-list-item__leading { + display: grid; + flex: none; + place-items: center; + width: 2.5rem; + height: 2.5rem; + border-radius: 9999px; + background-color: var(--color-secondary-container); + color: var(--color-on-secondary-container); +} + +.m3-list-item__leading > svg { + width: 1.5rem; + height: 1.5rem; +} + +.m3-list-item__body { + display: flex; + flex-direction: column; + gap: 0.125rem; + min-width: 0; +} + +/* Search bar (opens the search view) ---------------------------------------- */ + +.m3-search-bar { + display: flex; + align-items: center; + gap: 1rem; + width: 100%; + max-width: 40rem; + min-height: 3.5rem; + padding-inline: 1rem; + border-radius: 9999px; + background-color: var(--color-surface-container-high); + box-shadow: var(--shadow-elevation-1); + color: var(--color-on-surface-variant); + cursor: pointer; + text-align: start; + @apply text-body-large; +} + +.m3-search-bar > svg { + flex: none; + width: 1.5rem; + height: 1.5rem; + color: var(--color-on-surface); +} + +/* Small helpers -------------------------------------------------------------- */ + +.m3-code-chip { + padding: 0.25rem 0.75rem; + border-radius: var(--radius-sm); + background-color: var(--color-surface-container-highest); + color: var(--color-on-surface-variant); + font-family: var(--font-mono); + @apply text-body-medium; +} + +.m3-skip-link { + position: fixed; + inset-block-start: 0.75rem; + inset-inline-start: 0.75rem; + z-index: 60; + padding: 0.625rem 1.5rem; + border-radius: 9999px; + background-color: var(--color-primary); + box-shadow: var(--shadow-elevation-3); + color: var(--color-on-primary); + text-decoration: none; + transform: translateY(-200%); + @apply text-label-large; +} + +.m3-skip-link:focus { + transform: none; +} diff --git a/src/assets/index.css b/src/assets/index.css index fc56345..1c7a623 100644 --- a/src/assets/index.css +++ b/src/assets/index.css @@ -1,14 +1,29 @@ -.slogan { - font-size: small; - color: var(--color-base-content); -} - #avatar { - border-radius: 100%; + width: 5rem; + height: 5rem; margin-inline: auto; + border-radius: 9999px; + box-shadow: 0 0 0 4px var(--color-primary-container); + object-fit: cover; } #avatar:hover { cursor: pointer; will-change: transform; } + +/* Destination cards on the home page: a tonal icon next to the label. */ +.m3-destination { + flex-direction: row; + align-items: center; + gap: 1rem; + padding: 1rem 1.25rem; + @apply text-title-medium; +} + +.m3-destination > svg { + flex: none; + width: 1.5rem; + height: 1.5rem; + color: var(--color-primary); +} diff --git a/src/assets/prose.css b/src/assets/prose.css new file mode 100644 index 0000000..871d2f2 --- /dev/null +++ b/src/assets/prose.css @@ -0,0 +1,195 @@ +/* Markdown article body. Block spacing is owned by the container so authors never write margins. */ +.post-content { + width: 100%; + max-width: 100%; + color: var(--color-on-surface); + font-size: 1rem; + line-height: 1.85; + letter-spacing: 0.01em; + overflow-wrap: anywhere; +} + +.post-content > * + * { + margin-top: 1rem; +} + +.post-content > br { + display: none; +} + +.post-content > :first-child { + margin-top: 0; +} + +.post-content > :last-child { + margin-bottom: 0; +} + +/* Headings */ +.post-content :is(h2, h3, h4, h5) { + color: var(--color-on-surface); + letter-spacing: 0; +} + +.post-content h2 { + @apply text-headline-small; +} + +.post-content h3 { + @apply text-title-large; +} + +.post-content h4 { + @apply text-title-medium; +} + +.post-content h5 { + @apply text-title-small; +} + +.post-content > :is(h2, h3, h4, h5) { + margin-top: 2rem; + margin-bottom: 0.75rem; +} + +/* Lists */ +.post-content :is(ul, ol) { + padding-inline-start: 1.5rem; +} + +.post-content ul { + list-style: disc; +} + +.post-content ol { + list-style: decimal; +} + +.post-content li::marker { + color: var(--color-on-surface-variant); +} + +.post-content li + li, +.post-content li > :is(ul, ol) { + margin-top: 0.4rem; +} + +.post-content .contains-task-list { + list-style: none; + padding-inline-start: 0; +} + +.post-content .task-list-item { + display: flex; + gap: 0.75rem; + align-items: flex-start; +} + +.post-content .task-list-item > input { + flex: none; + width: 1.125rem; + height: 1.125rem; + margin-top: 0.4rem; +} + +/* Quotes and rules */ +.post-content blockquote { + padding: 0.75rem 1rem; + border-inline-start: 0.25rem solid var(--color-primary); + border-radius: var(--radius-xs) var(--radius-md) var(--radius-md) var(--radius-xs); + background-color: var(--color-surface-container-high); + color: var(--color-on-surface-variant); +} + +.post-content hr { + margin-block: 2rem; + border-color: var(--color-outline-variant); +} + +/* Media and tables */ +.post-content img, +.post-content iframe, +.post-content table, +.post-content pre { + width: 100%; +} + +.post-content img { + border-radius: var(--radius-md); +} + +.post-content table { + display: block; + overflow-x: auto; + border-collapse: collapse; +} + +.post-content :is(th, td) { + padding: 0.6rem 0.75rem; + border: 1px solid var(--color-outline-variant); + text-align: start; +} + +.post-content th { + background-color: var(--color-surface-container-high); + color: var(--color-on-surface); + font-weight: 500; +} + +/* Links stay underlined so they never rely on colour alone. */ +.post-content a { + color: var(--color-primary); + text-decoration: underline; + text-decoration-thickness: 0.1em; + text-underline-offset: 0.2em; + transition: color 150ms var(--ease-standard); +} + +.post-content a:hover { + color: var(--color-on-primary-container); + text-decoration-thickness: 0.15em; +} + +/* Math */ +.post-content .katex-display { + max-width: 100%; + overflow-x: auto; + padding-block: 0.25rem; +} + +/* Code: Shiki emits both themes as CSS variables, so the active colour scheme picks one. */ +.post-content :not(pre) > code { + margin-inline: 0.2rem; + padding: 0.125rem 0.375rem; + border-radius: var(--radius-xs); + background-color: var(--color-surface-container-highest); + color: var(--color-on-surface); + font-family: var(--font-mono); + font-size: 0.875em; + letter-spacing: 0; + word-break: break-word; +} + +.astro-code { + max-width: 100%; + padding: 1rem; + overflow-x: auto; + border: 1px solid var(--color-outline-variant); + border-radius: var(--radius-md); + background-color: light-dark(var(--shiki-light-bg), var(--shiki-dark-bg)); + color: light-dark(var(--shiki-light), var(--shiki-dark)); + font-family: var(--font-mono); + font-size: 0.875rem; + line-height: 1.6; + letter-spacing: 0; +} + +.astro-code code { + font-family: inherit; + word-break: normal; + overflow-wrap: normal; +} + +.astro-code span { + color: light-dark(var(--shiki-light), var(--shiki-dark)); +} diff --git a/src/assets/tokens.css b/src/assets/tokens.css new file mode 100644 index 0000000..0306b64 --- /dev/null +++ b/src/assets/tokens.css @@ -0,0 +1,140 @@ +/* + * Material Design 3 design tokens. + * + * Colour roles follow the M3 baseline scheme (seed colour #6750A4, tonal-spot + * palettes, generated with @material/material-color-utilities). Each role is written + * once with light-dark(): the light value follows `color-scheme`, which the + * theme toggle sets through html[data-theme]. To re-theme the site, replace the + * hex pairs below with the output for another seed colour. + * + * Everything is declared `static` so the plain-CSS components can read the + * variables even when no utility class happens to use them. + */ +@theme static { + --font-sans: "Roboto Variable", Roboto, "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", + "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif; + --font-mono: "Roboto Mono Variable", "Roboto Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, + "Noto Sans Mono CJK SC", monospace; + + /* Colour roles */ + --color-*: initial; + --color-primary: light-dark(#6750A4, #CFBCFF); + --color-on-primary: light-dark(#FFFFFF, #381E72); + --color-primary-container: light-dark(#E9DDFF, #4F378A); + --color-on-primary-container: light-dark(#22005D, #E9DDFF); + --color-secondary: light-dark(#625B71, #CBC2DB); + --color-on-secondary: light-dark(#FFFFFF, #332D41); + --color-secondary-container: light-dark(#E8DEF8, #4A4458); + --color-on-secondary-container: light-dark(#1E192B, #E8DEF8); + --color-tertiary: light-dark(#7E5260, #EFB8C8); + --color-on-tertiary: light-dark(#FFFFFF, #4A2532); + --color-tertiary-container: light-dark(#FFD9E3, #633B48); + --color-on-tertiary-container: light-dark(#31101D, #FFD9E3); + --color-error: light-dark(#BA1A1A, #FFB4AB); + --color-on-error: light-dark(#FFFFFF, #690005); + --color-error-container: light-dark(#FFDAD6, #93000A); + --color-on-error-container: light-dark(#410002, #FFDAD6); + --color-surface: light-dark(#FDF7FF, #141218); + --color-on-surface: light-dark(#1D1B20, #E6E0E9); + --color-surface-variant: light-dark(#E7E0EB, #49454E); + --color-on-surface-variant: light-dark(#49454E, #CAC4CF); + --color-outline: light-dark(#7A757F, #948F99); + --color-outline-variant: light-dark(#CAC4CF, #49454E); + --color-inverse-surface: light-dark(#322F35, #E6E0E9); + --color-inverse-on-surface: light-dark(#F5EFF7, #322F35); + --color-inverse-primary: light-dark(#CFBCFF, #6750A4); + --color-surface-dim: light-dark(#DED8E0, #141218); + --color-surface-bright: light-dark(#FDF7FF, #3B383E); + --color-surface-container-lowest: light-dark(#FFFFFF, #0F0D13); + --color-surface-container-low: light-dark(#F8F2FA, #1D1B20); + --color-surface-container: light-dark(#F2ECF4, #211F24); + --color-surface-container-high: light-dark(#ECE6EE, #2B292F); + --color-surface-container-highest: light-dark(#E6E0E9, #36343A); + + /* Type scale: size / line height / tracking / weight */ + --text-*: initial; + --text-display-large: 3.5625rem; + --text-display-large--line-height: 4rem; + --text-display-large--letter-spacing: -0.016rem; + --text-display-large--font-weight: 400; + --text-display-medium: 2.8125rem; + --text-display-medium--line-height: 3.25rem; + --text-display-medium--letter-spacing: 0; + --text-display-medium--font-weight: 400; + --text-display-small: 2.25rem; + --text-display-small--line-height: 2.75rem; + --text-display-small--letter-spacing: 0; + --text-display-small--font-weight: 400; + --text-headline-large: 2rem; + --text-headline-large--line-height: 2.5rem; + --text-headline-large--letter-spacing: 0; + --text-headline-large--font-weight: 400; + --text-headline-medium: 1.75rem; + --text-headline-medium--line-height: 2.25rem; + --text-headline-medium--letter-spacing: 0; + --text-headline-medium--font-weight: 400; + --text-headline-small: 1.5rem; + --text-headline-small--line-height: 2rem; + --text-headline-small--letter-spacing: 0; + --text-headline-small--font-weight: 400; + --text-title-large: 1.375rem; + --text-title-large--line-height: 1.75rem; + --text-title-large--letter-spacing: 0; + --text-title-large--font-weight: 400; + --text-title-medium: 1rem; + --text-title-medium--line-height: 1.5rem; + --text-title-medium--letter-spacing: 0.009rem; + --text-title-medium--font-weight: 500; + --text-title-small: 0.875rem; + --text-title-small--line-height: 1.25rem; + --text-title-small--letter-spacing: 0.006rem; + --text-title-small--font-weight: 500; + --text-label-large: 0.875rem; + --text-label-large--line-height: 1.25rem; + --text-label-large--letter-spacing: 0.006rem; + --text-label-large--font-weight: 500; + --text-label-medium: 0.75rem; + --text-label-medium--line-height: 1rem; + --text-label-medium--letter-spacing: 0.031rem; + --text-label-medium--font-weight: 500; + --text-label-small: 0.6875rem; + --text-label-small--line-height: 1rem; + --text-label-small--letter-spacing: 0.031rem; + --text-label-small--font-weight: 500; + --text-body-large: 1rem; + --text-body-large--line-height: 1.5rem; + --text-body-large--letter-spacing: 0.031rem; + --text-body-large--font-weight: 400; + --text-body-medium: 0.875rem; + --text-body-medium--line-height: 1.25rem; + --text-body-medium--letter-spacing: 0.016rem; + --text-body-medium--font-weight: 400; + --text-body-small: 0.75rem; + --text-body-small--line-height: 1rem; + --text-body-small--letter-spacing: 0.025rem; + --text-body-small--font-weight: 400; + + /* Shape scale (rounded-xs ... rounded-xl; rounded-full stays a pill) */ + --radius-*: initial; + --radius-xs: 0.25rem; + --radius-sm: 0.5rem; + --radius-md: 0.75rem; + --radius-lg: 1rem; + --radius-xl: 1.75rem; + + /* Elevation levels 1-5 */ + --shadow-*: initial; + --shadow-elevation-1: 0 1px 2px 0 rgb(0 0 0 / 0.3), 0 1px 3px 1px rgb(0 0 0 / 0.15); + --shadow-elevation-2: 0 1px 2px 0 rgb(0 0 0 / 0.3), 0 2px 6px 2px rgb(0 0 0 / 0.15); + --shadow-elevation-3: 0 1px 3px 0 rgb(0 0 0 / 0.3), 0 4px 8px 3px rgb(0 0 0 / 0.15); + --shadow-elevation-4: 0 2px 3px 0 rgb(0 0 0 / 0.3), 0 6px 10px 4px rgb(0 0 0 / 0.15); + --shadow-elevation-5: 0 4px 4px 0 rgb(0 0 0 / 0.3), 0 8px 12px 6px rgb(0 0 0 / 0.15); + + /* Motion easing */ + --ease-*: initial; + --ease-standard: cubic-bezier(0.2, 0, 0, 1); + --ease-standard-decelerate: cubic-bezier(0, 0, 0, 1); + --ease-standard-accelerate: cubic-bezier(0.3, 0, 1, 1); + --ease-emphasized-decelerate: cubic-bezier(0.05, 0.7, 0.1, 1); + --ease-emphasized-accelerate: cubic-bezier(0.3, 0, 0.8, 0.15); +} diff --git a/src/components/Card.astro b/src/components/Card.astro index fe80f2f..0681aa6 100644 --- a/src/components/Card.astro +++ b/src/components/Card.astro @@ -1,11 +1,12 @@ --- +interface Props { + variant?: "elevated" | "filled" | "outlined"; + class?: string; +} +const { variant = "elevated", class: className } = Astro.props; --- -
-
-
- -
-
+
+
diff --git a/src/components/Comments.astro b/src/components/Comments.astro index 9238b74..ff0be1c 100644 --- a/src/components/Comments.astro +++ b/src/components/Comments.astro @@ -3,7 +3,7 @@ import "../assets/Comments.css"; import "@waline/client/waline.css"; --- -
+
diff --git a/src/components/Placeholder.astro b/src/components/Placeholder.astro deleted file mode 100644 index 5ab194e..0000000 --- a/src/components/Placeholder.astro +++ /dev/null @@ -1,3 +0,0 @@ ---- ---- -
\ No newline at end of file diff --git a/src/components/PostCard.astro b/src/components/PostCard.astro index 59dfb7b..a077d6e 100644 --- a/src/components/PostCard.astro +++ b/src/components/PostCard.astro @@ -10,20 +10,18 @@ interface Props { const { post, showTopic = false, attrs = {} } = Astro.props; --- - -
{post.date}
-
{post.title}
- {showTopic && post.topic &&
主题:{post.topic}
} +
+

+ + {showTopic && post.topic && · 主题:{post.topic}} +

+

{post.title}

+ {post.description &&

{post.description}

} {post.tags.length > 0 && ( -
+
{post.tags.map((tag) => ( - {tag} + {tag} ))}
)} - {post.description &&

{post.description}

}
diff --git a/src/components/SearchModal.astro b/src/components/SearchModal.astro index f20ed5d..197802a 100644 --- a/src/components/SearchModal.astro +++ b/src/components/SearchModal.astro @@ -1,38 +1,34 @@ --- -import "../assets/SearchModal.css"; -import "../assets/PostList.css"; +import { Icon } from "astro-icon/components"; --- - - - - - + + + diff --git a/src/pages/posts/index.astro b/src/pages/posts/index.astro index 57af5ef..4c7af3b 100644 --- a/src/pages/posts/index.astro +++ b/src/pages/posts/index.astro @@ -1,7 +1,5 @@ --- import BaseLayout from "../../layouts/BaseLayout.astro"; -import "../../assets/PostList.css"; -import Card from "../../components/Card.astro"; import { Icon } from 'astro-icon/components'; import SearchModal from "../../components/SearchModal.astro"; import PostCard from "../../components/PostCard.astro"; @@ -9,16 +7,19 @@ import { posts } from "../../data/posts"; --- - -

文章总览

-
- 文章标签 - 文章专栏 - +
+

文章总览

+ + - -
- {posts.map((post) => )} -
- +
+ +
+ {posts.map((post) => )} +
diff --git a/src/pages/posts/tags.astro b/src/pages/posts/tags.astro index 3663f51..3b04dad 100644 --- a/src/pages/posts/tags.astro +++ b/src/pages/posts/tags.astro @@ -1,43 +1,32 @@ --- import BaseLayout from "../../layouts/BaseLayout.astro"; -import "../../assets/PostList.css"; -import Card from "../../components/Card.astro"; import PostCard from "../../components/PostCard.astro"; +import { Icon } from 'astro-icon/components'; import { posts } from "../../data/posts"; const tags = [...new Set(posts.flatMap((post) => post.tags))].sort((a, b) => a.localeCompare(b)); --- - -

文章标签

-
- {tags.map((tag) => ( - ))}
-
-
- {posts.map((post) => ( - - ))} -
-
+
+ +
+ {posts.map((post) => ( + + ))} +
diff --git a/src/pages/posts/topic.astro b/src/pages/posts/topic.astro index c887847..b3b1eb3 100644 --- a/src/pages/posts/topic.astro +++ b/src/pages/posts/topic.astro @@ -1,43 +1,32 @@ --- import BaseLayout from "../../layouts/BaseLayout.astro"; -import "../../assets/PostList.css"; -import Card from "../../components/Card.astro"; import PostCard from "../../components/PostCard.astro"; +import { Icon } from 'astro-icon/components'; import { posts } from "../../data/posts"; const topics = [...new Set(posts.map((post) => post.topic).filter(Boolean))].sort((a, b) => a.localeCompare(b)); --- - -

文章专栏

-
- {topics.map((topic) => ( - ))}
-
-
- {posts.map((post) => ( - - ))} -
-
+
+ +
+ {posts.map((post) => ( + + ))} +
diff --git a/src/scripts/postFilter.ts b/src/scripts/postFilter.ts index d733652..e76a8bd 100644 --- a/src/scripts/postFilter.ts +++ b/src/scripts/postFilter.ts @@ -4,7 +4,6 @@ export type PostFilterOptions = { summaryId: string; noun: string; matchMode: "includes" | "equals"; - hoverClass: string; }; export function initPostFilter(options: PostFilterOptions): void { @@ -14,12 +13,7 @@ export function initPostFilter(options: PostFilterOptions): void { const setActiveButton = (active: string): void => { buttons.forEach((button) => { - const isActive = button.getAttribute(options.buttonAttr) === active; - button.setAttribute("aria-pressed", String(isActive)); - button.classList.toggle("border-white", isActive); - button.classList.toggle("list-btn-active", isActive); - button.classList.toggle("border-base-content/10", !isActive); - button.classList.toggle(options.hoverClass, !isActive); + button.setAttribute("aria-pressed", String(button.getAttribute(options.buttonAttr) === active)); }); }; diff --git a/tests/site.spec.ts b/tests/site.spec.ts index 6062ae6..423b491 100644 --- a/tests/site.spec.ts +++ b/tests/site.spec.ts @@ -40,7 +40,7 @@ test("pages expose the expected document landmarks", async ({ page }) => { test("search is keyboard accessible and searches article bodies", async ({ page }) => { await page.goto("/posts/"); - const trigger = page.getByRole("button", { name: "文章搜索" }); + const trigger = page.getByRole("button", { name: "搜索文章" }); await trigger.focus(); await expect(trigger).toBeFocused(); await page.keyboard.press("Enter"); @@ -63,7 +63,7 @@ test("search is keyboard accessible and searches article bodies", async ({ page test("search results do not overlap the search input", async ({ page }) => { await page.goto("/posts/"); - await page.getByRole("button", { name: "文章搜索" }).click(); + await page.getByRole("button", { name: "搜索文章" }).click(); await expect(page.locator("#search_results a").first()).toBeVisible(); // Read both rects in one frame: the dialog is still animating when it opens. @@ -75,6 +75,58 @@ test("search results do not overlap the search input", async ({ page }) => { expect(gap).toBeGreaterThanOrEqual(0); }); +test("search view can be closed from its controls and cleared", async ({ page }) => { + await page.goto("/posts/"); + const trigger = page.getByRole("button", { name: "搜索文章" }); + const dialog = page.getByRole("dialog", { name: "搜索文章" }); + const input = page.getByRole("searchbox", { name: "搜索文章内容、标签或专栏" }); + const clear = page.getByRole("button", { name: "清除搜索内容" }); + + await trigger.click(); + await expect(clear).toBeHidden(); + await input.fill("FastMCP"); + await expect(clear).toBeVisible(); + await clear.click(); + await expect(input).toHaveValue(""); + await expect(input).toBeFocused(); + await expect(clear).toBeHidden(); + + await page.getByRole("button", { name: "关闭搜索" }).click(); + await expect(dialog).toBeHidden(); + await expect(trigger).toBeFocused(); + + // Outside the docked view (desktop) the backdrop closes it too; on phones the view is full screen. + if ((page.viewportSize()?.width ?? 0) >= 640) { + await trigger.click(); + await expect(dialog).toBeVisible(); + await page.mouse.click(8, 500); + await expect(dialog).toBeHidden(); + } +}); + +test("theme toggle switches, persists and reflects its state", async ({ page }) => { + await page.emulateMedia({ colorScheme: "light" }); + await page.goto("/"); + const toggle = page.getByRole("button", { name: "深色模式" }); + const root = page.locator("html"); + + await expect(root).toHaveAttribute("data-theme", "light"); + await expect(toggle).toHaveAttribute("aria-pressed", "false"); + + await toggle.click(); + await expect(root).toHaveAttribute("data-theme", "dark"); + await expect(toggle).toHaveAttribute("aria-pressed", "true"); + const surface = await page.evaluate(() => getComputedStyle(document.body).backgroundColor); + expect(surface).toBe("rgb(20, 18, 24)"); + + await page.reload(); + await expect(root).toHaveAttribute("data-theme", "dark"); + await expect(page.getByRole("button", { name: "深色模式" })).toHaveAttribute("aria-pressed", "true"); + + await page.getByRole("button", { name: "深色模式" }).click(); + await expect(root).toHaveAttribute("data-theme", "light"); +}); + test("post filters expose their active state", async ({ page }) => { await page.goto("/posts/tags/"); const tag = page.getByRole("button", { name: "AI底层" });