Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# 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/) 规范。

## 特性

- 文章内容使用 Markdown 编写
- 自动生成文章列表与文章页
- 支持标签、专题、日期排序
- 内置代码高亮与 KaTeX 数学公式
- 使用 daisyUI 主题,并支持本地 `localStorage` 记忆
- Material Design 3 设计令牌(色彩角色、字阶、形状、层级与动效),支持浅色 / 深色主题并记忆选择
- 顶栏、按钮、卡片、筛选芯片、搜索视图等组件均按 M3 规范实现
- 带有评论组件接入位

## 技术栈

- Astro 7
- Tailwind CSS v4
- daisyUI 5
- Roboto(`@fontsource-variable`,自托管)
- remark-breaks
- astro-icon
- Waline
Expand Down Expand Up @@ -63,7 +64,7 @@ npm run verify

```text
src/
assets/ 全局样式与组件样式
assets/ 设计令牌(tokens.css)、基础样式与各组件样式
components/ 可复用组件
layouts/ 页面布局
pages/ 路由页面与文章内容
Expand All @@ -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`,避免闪烁)

## 说明

Expand Down
7 changes: 6 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Loading
Loading