|
| 1 | +# 发布到 GitHub Pages 指南 |
| 2 | + |
| 3 | +## 快速开始 |
| 4 | + |
| 5 | +### 方法 1:使用 Windows 脚本(推荐) |
| 6 | + |
| 7 | +直接运行: |
| 8 | +``` |
| 9 | +bin\publish-to-github-pages.bat |
| 10 | +``` |
| 11 | + |
| 12 | +### 方法 2:使用 Bash 脚本(Git Bash / WSL) |
| 13 | + |
| 14 | +```bash |
| 15 | +chmod +x bin/publish-to-github-pages |
| 16 | +./bin/publish-to-github-pages |
| 17 | +``` |
| 18 | + |
| 19 | +## 首次设置 |
| 20 | + |
| 21 | +### 1. 确保 GitHub Pages 已启用 |
| 22 | + |
| 23 | +1. 打开你的 GitHub 仓库设置 |
| 24 | +2. 进入 **Settings** → **Pages** |
| 25 | +3. 在 **Source** 下选择: |
| 26 | + - Branch: `gh-pages` |
| 27 | + - Folder: `/docs` 或 `/ (root)` |
| 28 | +4. 点击 **Save** |
| 29 | + |
| 30 | +### 2. 调整 hosting-base-path |
| 31 | + |
| 32 | +在脚本中找到这一行: |
| 33 | +```bash |
| 34 | +--hosting-base-path the-swift-programming-language-in-chinese-1 |
| 35 | +``` |
| 36 | + |
| 37 | +改为你的**仓库名称**(如果仓库名不同的话)。 |
| 38 | + |
| 39 | +### 3. 第一次运行 |
| 40 | + |
| 41 | +脚本会自动: |
| 42 | +1. 创建 `gh-pages` 分支(如果不存在) |
| 43 | +2. 使用 `--experimental-enable-custom-templates` 构建文档 |
| 44 | +3. 将构建结果复制到 `gh-pages` 分支的 `docs` 目录 |
| 45 | +4. 提交并推送到 GitHub |
| 46 | + |
| 47 | +## 访问你的文档 |
| 48 | + |
| 49 | +发布成功后,访问: |
| 50 | +``` |
| 51 | +https://你的用户名.github.io/the-swift-programming-language-in-chinese-1/docs/documentation/the-swift-programming-language |
| 52 | +``` |
| 53 | + |
| 54 | +## 关键差异说明 |
| 55 | + |
| 56 | +相比原版脚本的修改: |
| 57 | +- ✅ `TSPL.docc` → `swift-6.docc`(中文版目录) |
| 58 | +- ✅ 添加 `--experimental-enable-custom-templates`(启用 header/footer) |
| 59 | +- ✅ 移除了 redirects 复制(如果你不需要) |
| 60 | +- ✅ 调整了 `--hosting-base-path` 为你的仓库名 |
| 61 | + |
| 62 | +## 本地预览(推荐先测试) |
| 63 | + |
| 64 | +发布前建议先本地预览: |
| 65 | +```bash |
| 66 | +# 使用之前创建的预览脚本 |
| 67 | +preview-with-header-footer.bat |
| 68 | +``` |
| 69 | + |
| 70 | +或手动: |
| 71 | +```bash |
| 72 | +docc preview swift-6.docc --experimental-enable-custom-templates |
| 73 | +``` |
| 74 | + |
| 75 | +## 故障排除 |
| 76 | + |
| 77 | +### 问题:没有看到 header 和 footer |
| 78 | +**解决**:确保构建命令包含 `--experimental-enable-custom-templates` |
| 79 | + |
| 80 | +### 问题:页面 404 |
| 81 | +**解决**: |
| 82 | +1. 检查 GitHub Pages 设置中的分支和文件夹 |
| 83 | +2. 确认 `--hosting-base-path` 与仓库名匹配 |
| 84 | +3. 等待几分钟让 GitHub Pages 部署 |
| 85 | + |
| 86 | +### 问题:样式不正确 |
| 87 | +**解决**:检查 `swift-6.docc/header.html` 和 `footer.html` 中的资源路径 |
| 88 | + |
| 89 | +## 自动化部署(可选) |
| 90 | + |
| 91 | +可以设置 GitHub Actions 自动发布。需要时可以参考官方仓库的 workflow 配置。 |
0 commit comments