|
| 1 | + |
| 2 | +# NavSphere |
| 3 | + |
| 4 | +## Overview |
| 5 | +NavSphere is a web application designed for managing navigation items and categories. It provides an intuitive interface for adding, editing, and organizing navigation entries, including site icons and descriptions. |
| 6 | + |
| 7 | +## Features |
| 8 | +- **Add/Edit Navigation Items**: Easily add or modify navigation items with titles, links, icons, and descriptions. |
| 9 | +- **Icon Management**: Upload or fetch icons for each navigation item. |
| 10 | +- **Drag-and-Drop Interface**: Reorder navigation items and categories using drag-and-drop functionality. |
| 11 | +- **Responsive Design**: Works seamlessly on various devices and screen sizes. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | +- Node.js (version x.x.x) |
| 17 | +- npm or yarn |
| 18 | + |
| 19 | +### Steps |
| 20 | +1. Clone the repository: |
| 21 | + ```bash |
| 22 | + git clone https://github.com/tianyaxiang/NavSphere.git |
| 23 | + |
| 24 | +```bash |
| 25 | +npm run dev |
| 26 | +# or |
| 27 | +yarn dev |
| 28 | +# or |
| 29 | +pnpm dev |
| 30 | +# or |
| 31 | +bun dev |
| 32 | +``` |
| 33 | + |
| 34 | +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. |
| 35 | + |
| 36 | +You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. |
| 37 | + |
| 38 | +This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. |
| 39 | + |
| 40 | +## Learn More |
| 41 | + |
| 42 | +To learn more about Next.js, take a look at the following resources: |
| 43 | + |
| 44 | +- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. |
| 45 | +- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. |
| 46 | + |
| 47 | +You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! |
| 48 | + |
| 49 | +## Deploy on Vercel |
| 50 | + |
| 51 | +The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. |
| 52 | + |
| 53 | +Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
| 54 | + |
| 55 | +## 本地开发配置 |
| 56 | + |
| 57 | +### 1. GitHub OAuth App 配置 |
| 58 | + |
| 59 | +1. 访问 [GitHub Developer Settings](https://github.com/settings/developers) |
| 60 | + - 点击右上角头像 |
| 61 | + - Settings |
| 62 | + - 左侧边栏底部 Developer settings |
| 63 | + - OAuth Apps |
| 64 | + - New OAuth App |
| 65 | + |
| 66 | +2. 填写应用信息: |
| 67 | + ``` |
| 68 | + Application name: 你的应用名称 |
| 69 | + Homepage URL: http://localhost:3000 |
| 70 | + Authorization callback URL: http://localhost:3000/api/auth/callback/github |
| 71 | + ``` |
| 72 | +
|
| 73 | +3. 创建后获取: |
| 74 | + - Client ID: 显示在应用详情页 |
| 75 | + - Client Secret: 点击 "Generate a new client secret" 生成 |
| 76 | +
|
| 77 | +### 2. GitHub 仓库配置 |
| 78 | +
|
| 79 | +1. 创建用于存储数据的仓库: |
| 80 | + - 访问 [GitHub New Repository](https://github.com/new) |
| 81 | + - 填写仓库名 |
| 82 | + - 选择 Public 或 Private |
| 83 | + - 创建仓库 |
| 84 | +
|
| 85 | +2. 获取仓库信息: |
| 86 | + ``` |
| 87 | + GITHUB_OWNER: 你的 GitHub 用户名 |
| 88 | + GITHUB_REPO: 仓库名 |
| 89 | + ``` |
| 90 | +
|
| 91 | +3. 创建 GitHub 组织(可选): |
| 92 | + - 访问 [GitHub New Organization](https://github.com/organizations/new) |
| 93 | + - 选择免费计划 |
| 94 | + - 填写组织名称 |
| 95 | + - 将需要访问的用户添加到组织 |
| 96 | +
|
| 97 | +### 3. 环境变量配置 |
| 98 | +
|
| 99 | +```env |
| 100 | +# GitHub OAuth App 配置 |
| 101 | +GITHUB_ID=从 OAuth App 获取的 Client ID |
| 102 | +GITHUB_SECRET=从 OAuth App 获取的 Client Secret |
| 103 | +
|
| 104 | +# GitHub 组织和仓库配置 |
| 105 | +GITHUB_ORG=你的组织名称(如果使用组织) |
| 106 | +GITHUB_OWNER=你的 GitHub 用户名 |
| 107 | +GITHUB_REPO=用于存储数据的仓库名 |
| 108 | +GITHUB_BRANCH=main |
| 109 | +
|
| 110 | +# NextAuth 配置 |
| 111 | +NEXTAUTH_URL=http://localhost:3000 |
| 112 | +NEXTAUTH_SECRET=使用以下命令生成: |
| 113 | +# openssl rand -base64 32 |
| 114 | +``` |
| 115 | + |
| 116 | +### 4. 权限配置 |
| 117 | + |
| 118 | +1. OAuth App 权限: |
| 119 | + - 在 OAuth App 设置页面 |
| 120 | + - 确保 `read:org` 和 `repo` 权限被勾选 |
| 121 | + |
| 122 | +2. 仓库权限: |
| 123 | + - 如果是私有仓库,确保 OAuth App 有访问权限 |
| 124 | + - 如果使用组织,确保 OAuth App 已在组织中安装 |
| 125 | + |
| 126 | +### 5. 注意事项 |
| 127 | + |
| 128 | +1. 本地开发和生产环境使用不同的 OAuth App |
| 129 | +2. 生产环境需要更新回调 URL 为实际域名 |
| 130 | +3. 确保 `.env.local` 不被提交到 Git |
| 131 | +4. 生产环境使用 Cloudflare Pages 的环�� |
| 132 | +5. 定期轮换 Client Secret 以提高安全性 |
| 133 | + |
| 134 | +## Cloudflare Pages 部署 |
| 135 | + |
| 136 | +1. 在 Cloudflare Pages 中创建新项目 |
| 137 | +2. 连接 GitHub 仓库 |
| 138 | +3. 设置构建命令: |
| 139 | + ```bash |
| 140 | + pnpm install && pnpm build |
| 141 | + ``` |
| 142 | +4. 设置环境变量: |
| 143 | + - GITHUB_ID |
| 144 | + - GITHUB_SECRET |
| 145 | + - GITHUB_OWNER |
| 146 | + - GITHUB_REPO |
| 147 | + - GITHUB_BRANCH |
| 148 | + - NEXTAUTH_URL (设置为你的域名) |
| 149 | + - NEXTAUTH_SECRET |
| 150 | +5. 部署项目 |
| 151 | + |
| 152 | +## 环境变量 |
| 153 | + |
| 154 | +需要配置以下环境变量: |
| 155 | + |
| 156 | +```env |
| 157 | +NEXTAUTH_URL=http://localhost:3000 |
| 158 | +NEXTAUTH_SECRET=your-secret-here |
| 159 | +GITHUB_ID=your-github-id |
| 160 | +GITHUB_SECRET=your-github-secret |
| 161 | +GITHUB_OWNER=your-github-username |
| 162 | +GITHUB_REPO=your-repo-name |
| 163 | +GITHUB_BRANCH=main |
| 164 | +``` |
| 165 | + |
| 166 | +## 开发 |
| 167 | + |
| 168 | +1. 安装依赖 |
| 169 | + |
| 170 | +```bash |
| 171 | +pnpm install |
| 172 | +``` |
| 173 | + |
| 174 | +2. 配置环境变量 |
| 175 | + |
| 176 | +```bash |
| 177 | +cp .env.example .env.local |
| 178 | +``` |
| 179 | + |
| 180 | +3. 启动开发服务器 |
| 181 | + |
| 182 | +```bash |
| 183 | +pnpm dev |
| 184 | +``` |
| 185 | + |
| 186 | +## 数据文件 |
| 187 | + |
| 188 | +项目使用 GitHub 仓库存储数据,需要以下数据文件: |
| 189 | + |
| 190 | +1. `app/data/db/navigation.json` - 导航数据 |
| 191 | +2. `app/data/db/resources.json` - 资源数据 |
| 192 | + |
| 193 | +这些文件会在首次提交到仓库时自动创建。 |
| 194 | + |
| 195 | +## 数据格式 |
| 196 | + |
| 197 | +### navigation.json |
| 198 | +```json |
| 199 | +[ |
| 200 | + { |
| 201 | + "id": "string", |
| 202 | + "title": "string", |
| 203 | + "icon": "string", |
| 204 | + "items": [ |
| 205 | + { |
| 206 | + "title": "string", |
| 207 | + "titleEn": "string", |
| 208 | + "description": "string", |
| 209 | + "descriptionEn": "string", |
| 210 | + "icon": "string", |
| 211 | + "href": "string" |
| 212 | + } |
| 213 | + ], |
| 214 | + "subCategories": [ |
| 215 | + { |
| 216 | + "id": "string", |
| 217 | + "title": "string", |
| 218 | + "items": [] |
| 219 | + } |
| 220 | + ] |
| 221 | + } |
| 222 | +] |
| 223 | +``` |
| 224 | + |
| 225 | +### resources.json |
| 226 | +```json |
| 227 | +[ |
| 228 | + { |
| 229 | + "id": "string", |
| 230 | + "title": "string", |
| 231 | + "items": [ |
| 232 | + { |
| 233 | + "title": "string", |
| 234 | + "description": "string", |
| 235 | + "icon": "string", |
| 236 | + "url": "string" |
| 237 | + } |
| 238 | + ] |
| 239 | + } |
| 240 | +] |
| 241 | +``` |
| 242 | + |
| 243 | +## 故障排除 |
| 244 | + |
| 245 | +### 导航数据加载失败 |
| 246 | + |
| 247 | +1. 检查环境变量配置 |
| 248 | + - GITHUB_OWNER 是否正确 |
| 249 | + - GITHUB_REPO 是否正确 |
| 250 | + - GITHUB_BRANCH 是否正确 |
| 251 | + |
| 252 | +2. 检查仓库权限 |
| 253 | + - 仓库是否公开 |
| 254 | + - OAuth App 是否有正确的权限 |
| 255 | + - Token 是否有效 |
| 256 | + |
| 257 | +3. 检查数据文件 |
| 258 | + - navigation.json 是否存在 |
| 259 | + - 文件格式是否正确 |
| 260 | + - 文件路径是否正确 |
| 261 | + |
| 262 | +4. 查看控制台日志 |
| 263 | + - 检查 API 请求是否成功 |
| 264 | + - 检查错误信息 |
| 265 | + - 检查返回的数据格式 |
0 commit comments