Skip to content

Commit 10c99c5

Browse files
committed
Fix 404 Error of English pages by github Actions.
1 parent a8312e7 commit 10c99c5

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed

.github/workflows/jekyll.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# 工作流名称
2+
name: Deploy Jekyll site to Pages
3+
4+
# 触发条件
5+
on:
6+
# 在推送到默认分支时触发
7+
push:
8+
branches: ["main"]
9+
# 允许手动触发
10+
workflow_dispatch:
11+
12+
# 权限设置
13+
permissions:
14+
contents: read
15+
pages: write
16+
id-token: write
17+
18+
# 并发设置,确保只有一个部署在进行
19+
concurrency:
20+
group: "pages"
21+
cancel-in-progress: false
22+
23+
# 任务定义
24+
jobs:
25+
# 构建任务
26+
build:
27+
runs-on: ubuntu-latest
28+
steps:
29+
# 1. 检出代码
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
# 2. 设置 Ruby 环境
34+
- name: Setup Ruby
35+
uses: ruby/setup-ruby@v1
36+
with:
37+
ruby-version: '3.0' # 指定 Ruby 版本
38+
bundler-cache: true # 自动运行 bundle install
39+
cache-version: 0 # 缓存版本
40+
41+
# 3. 设置 Node.js 环境(如果需要)
42+
- name: Setup Node
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: "20"
46+
47+
# 4. 安装依赖
48+
- name: Install dependencies
49+
run: |
50+
bundle install
51+
npm install -g jekyll
52+
53+
# 5. 构建站点
54+
- name: Build with Jekyll
55+
run: bundle exec jekyll build --baseurl ""
56+
env:
57+
JEKYLL_ENV: production
58+
59+
# 6. 上传构建产物
60+
- name: Upload artifact
61+
uses: actions/upload-pages-artifact@v3
62+
with:
63+
path: "./_site"
64+
65+
# 部署任务
66+
deploy:
67+
# 依赖构建任务
68+
needs: build
69+
70+
# 部署环境
71+
environment:
72+
name: github-pages
73+
url: ${{ steps.deployment.outputs.page_url }}
74+
75+
runs-on: ubuntu-latest
76+
77+
steps:
78+
# 1. 部署到 GitHub Pages
79+
- name: Deploy to GitHub Pages
80+
id: deployment
81+
uses: actions/deploy-pages@v4

DEPLOY.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# GitHub Pages 部署配置指南
2+
3+
## 问题描述
4+
5+
使用 GitHub Pages 默认的 Jekyll 构建环境时,polyglot 插件无法正常工作,导致英文页面无法生成在 `/en/` 目录下。
6+
7+
## 解决方案
8+
9+
使用 GitHub Actions 自定义构建流程,确保使用正确的 Ruby 环境和插件。
10+
11+
## 配置步骤
12+
13+
### 1. 确保 workflow 文件已创建
14+
15+
检查 `.github/workflows/jekyll.yml` 文件是否存在。这个文件定义了自定义构建流程。
16+
17+
### 2. 配置 GitHub Pages 使用 GitHub Actions
18+
19+
1. 打开 GitHub 仓库页面
20+
2. 点击 **Settings** > **Pages**
21+
3.**Build and deployment** 部分:
22+
- **Source**: 选择 "GitHub Actions"(而不是 "Deploy from a branch")
23+
4. 保存设置
24+
25+
### 3. 提交并推送 workflow 文件
26+
27+
```bash
28+
git add .github/workflows/jekyll.yml
29+
git commit -m "Add GitHub Actions workflow for Jekyll build"
30+
git push origin main
31+
```
32+
33+
### 4. 验证部署
34+
35+
1. 推送后,GitHub Actions 会自动触发构建
36+
2. 查看构建进度:
37+
- 打开 GitHub 仓库页面
38+
- 点击 **Actions** 标签
39+
- 查看 "Deploy Jekyll site to Pages" 工作流
40+
3. 构建成功后,访问网站验证:
41+
- 中文首页: `https://renchzhao.github.io/`
42+
- 英文首页: `https://renchzhao.github.io/en/`
43+
- 中文简历: `https://renchzhao.github.io/cv/`
44+
- 英文简历: `https://renchzhao.github.io/en/cv/`
45+
46+
## 工作原理
47+
48+
GitHub Actions workflow 会:
49+
50+
1. **检出代码**: 获取最新的仓库代码
51+
2. **设置 Ruby 环境**: 安装指定版本的 Ruby 和 bundler
52+
3. **安装依赖**: 运行 `bundle install` 安装所有 gem 包,包括 polyglot
53+
4. **构建站点**: 运行 `bundle exec jekyll build` 构建静态网站
54+
5. **部署**: 将构建结果上传到 GitHub Pages
55+
56+
## 故障排除
57+
58+
### 构建失败
59+
60+
如果构建失败:
61+
62+
1. 查看 Actions 日志,找出错误信息
63+
2. 确保 Gemfile 中包含了所有必要的插件
64+
3. 确保 _config.yml 配置正确
65+
66+
### 页面未生成
67+
68+
如果某些页面未生成:
69+
70+
1. 检查页面的 Front Matter 是否包含 `lang` 属性
71+
2. 检查 permalink 配置是否正确(不应包含语言前缀)
72+
3. 检查文件路径是否正确
73+
74+
## 参考资料
75+
76+
- [GitHub Pages 官方文档](https://docs.github.com/zh/pages)
77+
- [Jekyll 构建流程](https://jekyllrb.com/docs/continuous-integration/github-actions/)
78+
- [polyglot 插件文档](https://github.com/untra/polyglot)
79+
80+
## 许可证
81+
82+
本项目基于 Jekyll 框架开发,Jekyll 采用 MIT 许可证。
83+
原始版权信息如下:
84+
> Copyright (c) 2008-present Tom Preston-Werner and Jekyll contributors

0 commit comments

Comments
 (0)