Skip to content
Closed
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
10 changes: 10 additions & 0 deletions .trae/rules/project_rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
- 项目目前使用了Giscus实现了评论功能。
- 我已经在Github Action secrets中配置了`BLOG_GITHUB_TOKEN` 、`BLOG_GITHUB_BRANCH`、`BLOG_GITHUB_REPO`、`BLOG_GITHUB_OWNER`这四个secret环境变量,他们分别是:该项目拥有repo权限的token,项目分支名,项目名称,项目作者。在github action编译项目时可以并推荐使用这些值,但在本地你可能无法使用这些值,所以你在本地编译时遇到错误不要烦恼,可以使用本地的env,而不是去修改代码

## 动态功能开发约束(GitHub Pages 静态部署)

- **禁止使用 API 路由提供动态数据**:`output: export` 模式下,Next.js API Routes 不会被打包到静态站点中。所有动态数据必须在构建时通过服务端组件读取并传递给客户端。
- **图片路径必须考虑 basePath**:当仓库不是 `*.github.io` 用户页时,GitHub Pages 会添加 `/${repoName}` 子路径。content.md 中应使用可移植的路径(如 `/moments/...`),在服务端渲染时通过 `NEXT_PUBLIC_BASE_PATH` 转换为实际可访问路径。
- **GitHub Token 安全**:`NEXT_PUBLIC_BLOG_GITHUB_TOKEN` 会在构建时被打包进静态 JS,任何访问者均可从源码获取。建议优先引导用户在页面会话中手动输入 Token(存储于 `sessionStorage`),仅将环境变量作为降级方案。
- **时间处理必须保留完整 ISO 8601 字符串**:不要在前置元数据处理阶段截断时间(如格式化为 `YYYY-MM-DD`),否则客户端相对时间("刚刚"、"5分钟前")会因精度丢失而计算错误。时区统一使用 UTC(`toISOString()`),客户端根据本地时区渲染。
- **禁止在 markdown 文件中嵌入 base64 图片**:base64 数据会急剧增加文件体积、拖慢构建和加载速度。图片应作为独立文件保存,content.md 中通过标准 Markdown 图片语法 `![alt](/path)` 引用。
- **XSS 防护**:`LazyMarkdown` 渲染用户提交的内容时,**禁止**启用 `rehype-raw` 直接渲染原始 HTML。如需兼容旧数据中的 HTML img 标签,应在传入 `ReactMarkdown` 前将其转换为 Markdown 语法。
- **本地开发与生产行为一致性**:本地 API(`/api/moments/local` 等)仅用于开发环境,应通过 `GITHUB_ACTIONS` / `VERCEL` 等 CI 环境变量明确禁用,避免与静态导出冲突。

## 调试代码
- 在每次修改并在dev环境测试通过后,请使用npm/pnpm run build确保生产环境能够正常编译。
- 在测试通过后请确保pnpm锁文件是最新的,防止生产环境无法下载新的依赖等问题
Expand Down
7 changes: 7 additions & 0 deletions debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[39816:39864:0609/000111.580:WARNING:t_skinfilemap.cpp(56)] SGRenderLog:CheckUpdate newMem.OpenMem failed, szNewMem:Local\sgime_skin.v3.filemap.sogouime err:系统错误2: 系统找不到指定的文件。
打开Filemap失败: Local\sgime_skin.v3.filemap.sogouime2411d641de7
[39816:39864:0609/000111.580:WARNING:t_skinfilemap.cpp(65)] SGRenderLog:CheckUpdate finish: old version:1
[39816:39864:0609/000111.580:WARNING:t_skinfilemap.cpp(67)] SGRenderLog:CheckUpdate finish: new version:3
[39816:39864:0609/000111.687:WARNING:t_skinfilemap.cpp(63)] SGRenderLog:CheckUpdate newMem.OpenMem Suc, szNewMem:Local\sgime_skin.Dpi144.v3.filemap.sogouime
[39816:39864:0609/000111.687:WARNING:t_skinfilemap.cpp(65)] SGRenderLog:CheckUpdate finish: old version:3
[39816:39864:0609/000111.687:WARNING:t_skinfilemap.cpp(67)] SGRenderLog:CheckUpdate finish: new version:3
19 changes: 7 additions & 12 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ const nextConfig = {
// 只在构建时启用静态导出,开发时禁用以避免 generateStaticParams 错误
...(process.env.NODE_ENV === "production" && {
output: "export",
// 忽略 API 路由在静态导出时的页面数据收集
webpack: (config: any) => {
config.ignoreWarnings = [{ module: /api\/moments\/detail/ }];
return config;
},
}),
trailingSlash: true,
// 环境变量配置,供客户端组件使用
Expand Down Expand Up @@ -61,13 +56,13 @@ const nextConfig = {
// 移除assetPrefix,basePath已经足够处理资源路径
}),
images: {
// 允许的外部图片域名
domains: [
"localhost",
"example.com",
"images.unsplash.com",
"cdn.jsdelivr.net",
"raw.githubusercontent.com",
// 允许的外部图片域名(使用 remotePatterns 替代已弃用的 domains)
remotePatterns: [
{ protocol: 'https', hostname: 'localhost' },
{ protocol: 'https', hostname: 'example.com' },
{ protocol: 'https', hostname: 'images.unsplash.com' },
{ protocol: 'https', hostname: 'cdn.jsdelivr.net' },
{ protocol: 'https', hostname: 'raw.githubusercontent.com' },
],
// 图片格式优化
formats: ["image/webp", "image/avif"],
Expand Down
Loading