# 筱周の网站 (XiaoZhou's Website) 个人主页 —— 终端 / 黑客风格,黑底 + emerald 主题,等宽字体 Geist。 - 首页 `/`:视差 Hero、打字机标题、导航卡片,以及「关于我 / 项目展示 / 联系我」三个区块。 - 更多 `/more`:应用聚合页,把自建的小工具集中到一个入口。 ## 技术栈 | 类别 | 选型 | | --- | --- | | 框架 | React 19 + TypeScript | | 构建 | Vite 8 | | 样式 | Tailwind CSS 4 | | 图标 | lucide-react | | 字体 | Geist Variable (`@fontsource-variable/geist`) | | 路由 | 自研轻量路由(零依赖,见 `src/router/`) | ## 快速开始 ```bash npm install # 安装依赖 npm run dev # 启动开发服务器(HMR) npm run build # 生产构建 + 后处理 npm run preview # 本地预览构建产物 npm run lint # ESLint 检查 ``` > 构建脚本为 `tsc -b && vite build && node scripts/postbuild.mjs`,最后一步会把 > `dist/index.html` 复制成 `dist/more/index.html`,用于静态托管,并把项目根目录 > `extra/` 里的所有文件复制进 `dist/`(见下方「额外静态文件」)。 ## 目录结构 ``` src/ ├── App.tsx 根组件:解析当前路由并渲染对应页面 ├── main.tsx React 挂载入口 ├── index.css Tailwind 入口 + 全局基础样式 ├── router/ 轻量路由 │ ├── routes.ts 路由表(页面的唯一数据源) │ ├── history.ts normalizePath / navigate / subscribe │ ├── useRoute.ts 基于 useSyncExternalStore 的路由 hook │ ├── Link.tsx 站内跳转链接组件 │ └── index.ts 统一导出 ├── components/ │ ├── Banner.tsx 首页 Hero(背景 + 打字机 + 导航卡片) │ ├── NavCard.tsx 导航卡片 │ ├── layout/ Header / Footer │ └── sections/ About / Projects / Contact 区块 ├── pages/ │ ├── HomePage.tsx 首页 │ └── MorePage.tsx /more 应用聚合页 ├── data/navigation.ts 首页导航卡片数据 ├── hooks/ useTypewriter / useParallax ├── types/index.ts NavItem 类型 └── assets/banner.png 全站背景图 extra/ 额外静态文件(构建时原样复制进 dist/) scripts/postbuild.mjs 构建后处理(生成 dist/more/index.html、复制 extra/) ``` ## 添加 Item 有 3 种情况,按你想加的东西选择。 ### 方式一:首页 Banner 上的导航卡片 编辑 `src/data/navigation.ts`,往 `NAV_ITEMS` 数组追加一项: ```ts import { LayoutDashboard, ListCollapse, BookOpen } from "lucide-react"; // 1. 引入图标 import type { NavItem } from "@/types"; export const NAV_ITEMS: NavItem[] = [ // ...已有项 { name: "Blog", // 卡片标题 desc: "我的博客", // 卡片副标题 path: "https://blog.xiaozhou233.cn", // 链接(见下方说明) Icon: BookOpen, // lucide 图标组件 color: "text-sky-400", // 图标颜色 borderHover: // hover 时的边框 + 光晕 "hover:border-sky-500/50 hover:shadow-[0_0_20px_rgba(56,189,248,0.2)]", }, ]; ``` 字段说明: | 字段 | 说明 | | --- | --- | | `name` | 卡片标题,同时作为 React `key`,**不要重复** | | `desc` | 卡片副标题 | | `path` | 以 `/` 开头 → 站内路由、当前页 SPA 跳转;其他(`http...`、`#`)→ 新标签页打开。由 `NavCard.tsx` 自动判断 | | `Icon` | 任意 `lucide-react` 图标组件 | | `color` | 图标 Tailwind 颜色类 | | `borderHover` | hover 的边框色 + 阴影类 | > 卡片网格会自动排版,无需改动布局。 ### 方式二:`/more` 页的应用卡片 编辑 `src/pages/MorePage.tsx`,需要动两个地方:图标定义和列表。 ```ts // 1. 在 appIcons 里加图标(SVG 内容,通常从 lucide 复制 path) const appIcons = { water: , atom: (<>...), book: , // 新增 }; // 2. 在 apps 数组里追加一项 const apps = [ // ...已有项 { name: "新应用", desc: "一句话描述", color: "#10b981", // 图标底色,渐变自动生成 link: "https://example.com", // 跳转地址 icon: appIcons.book, // 指向上面定义的图标 }, ]; ``` | 字段 | 说明 | | --- | --- | | `name` | 应用名,同时作为 React `key`,**不要重复** | | `desc` | 一句话描述 | | `color` | 图标十六进制底色,卡片会自动生成同色渐变与光晕 | | `link` | 目标地址(站内相对路径或完整 URL) | | `icon` | 引用 `appIcons` 里的 SVG 片段 | ### 方式三:新增一个独立页面(路由) 如果卡片要指向站内新页面(例如 `/blog`): **1. 新建页面组件**,如 `src/pages/BlogPage.tsx`。 **2. 注册路由**,在 `src/router/routes.ts` 的 `ROUTES` 追加: ```ts import BlogPage from "@/pages/BlogPage"; export const ROUTES: RouteDefinition[] = [ // ...已有路由 { name: "blog", path: "/blog", pattern: /^\/blog$/, // 路径匹配正则 title: "博客 - 筱周の网站", // 会自动设置 document.title Component: BlogPage, }, ]; ``` **3.(可选)让该路径能被直接访问。** 目前 `scripts/postbuild.mjs` 只为 `/more` 生成了静态入口。若希望直接打开 `https://你的域名/blog` 也能命中(而不是只从首页点进去), 照抄一份: ```js const blogDir = resolve(root, "dist", "blog"); mkdirSync(blogDir, { recursive: true }); writeFileSync(resolve(blogDir, "index.html"), indexHtml); ``` > 如果托管平台已配置 SPA history fallback(如 Cloudflare Pages / Netlify 的 rewrite), > 这一步可以省略。 ## 额外静态文件(`extra/`) 如果有一些**不属于源码、但希望每次构建都出现在站点里**的文件(例如独立的小工具页面、 验证文件、下载资源等),把它们放进项目根目录的 `extra/` 即可,无需改配置: ``` extra/ ├── hello.txt -> dist/hello.txt ├── tools/ -> dist/tools/ │ └── index.html -> dist/tools/index.html └── .well-known/ -> dist/.well-known/ └── verification -> dist/.well-known/verification ``` - **构建时**:`scripts/postbuild.mjs` 会递归复制 `extra/` 里的所有内容到 `dist/` 根目录 (是合并,不会生成 `dist/extra/`)。所以 `extra/a.txt` 最终可访问路径是 `/a.txt`。 - **目录不存在时**:自动跳过,构建不会报错。空目录不会被 git 跟踪,仓库里用 `extra/.gitkeep` 占位。 - **只影响构建产物**:`extra/` 不参与 `npm run dev`,文件不会出现在开发服务器上; 若开发时也要能访问,请改用 Vite 原生的 `public/` 目录。 - **注意**:`extra/` 中的文件会覆盖 `dist/` 里的同名文件。比如放一个 `index.html` 会 覆盖站点首页,请避免。 ## 路由 路由是自研的零依赖实现,核心思路: - **路由表唯一数据源**:`src/router/routes.ts` 里的 `ROUTES`,每条包含 `path`、 `pattern`、`title`、`Component`。加页面只改这里。 - **路径归一化**:`normalizePath()` 把 `/more`、`/more/`、`/more/index.html` 统一成 `/more`。 - **响应式**:`useRoute()` 基于 `useSyncExternalStore`,监听 `popstate`, 浏览器前进/后退正常工作。 - **站内跳转**:用 `src/router/Link.tsx` 的 `` 做客户端跳转; 中键 / Ctrl 点击等仍会走浏览器默认行为(新标签页)。 - **兜底**:未知路径回落到首页(`FALLBACK_ROUTE`)。 ## 样式约定 - 主色 `emerald`,背景 `black`,卡片统一使用玻璃拟态: `bg-white/5 border border-white/5 backdrop-blur-sm rounded-2xl`。 - 强调/交互用 emerald 光晕:`hover:border-emerald-500/30 hover:shadow-[0_0_25px_rgba(52,211,153,0.1)]`。 - 标题、终端提示符用 `font-mono`;正文描述用 `font-sans`(Geist)。 - Tailwind 4 语法:渐变用 `bg-linear-to-r`,字体族通过 `@theme` 覆盖。 ## 部署 ```bash npm run build ``` 产物在 `dist/`,可直接托管到任意静态平台。注意构建会自动把 `dist/index.html` 复制成 `dist/more/index.html`,保证 `/more` 可直达,并把 `extra/` 的内容合并进 `dist/`。 ## 备注 - 全站背景图为 `src/assets/banner.png`,由 Vite 打包(带 hash)。 - `index.html` 中接入了 umami 访问统计(`umami.xiaozhou233.cn`),如不需要可移除该 `