使用 GitHub Pages 默认的 Jekyll 构建环境时,polyglot 插件无法正常工作,导致英文页面无法生成在 /en/ 目录下。
使用 GitHub Actions 自定义构建流程,确保使用正确的 Ruby 环境和插件。
检查 .github/workflows/jekyll.yml 文件是否存在。这个文件定义了自定义构建流程。
- 打开 GitHub 仓库页面
- 点击 Settings > Pages
- 在 Build and deployment 部分:
- Source: 选择 "GitHub Actions"(而不是 "Deploy from a branch")
- 保存设置
git add .github/workflows/jekyll.yml
git commit -m "Add GitHub Actions workflow for Jekyll build"
git push origin main- 推送后,GitHub Actions 会自动触发构建
- 查看构建进度:
- 打开 GitHub 仓库页面
- 点击 Actions 标签
- 查看 "Deploy Jekyll site to Pages" 工作流
- 构建成功后,访问网站验证:
- 中文首页:
https://renchzhao.github.io/ - 英文首页:
https://renchzhao.github.io/en/ - 中文简历:
https://renchzhao.github.io/cv/ - 英文简历:
https://renchzhao.github.io/en/cv/
- 中文首页:
GitHub Actions workflow 会:
- 检出代码: 获取最新的仓库代码
- 设置 Ruby 环境: 安装指定版本的 Ruby 和 bundler
- 安装依赖: 运行
bundle install安装所有 gem 包,包括 polyglot - 构建站点: 运行
bundle exec jekyll build构建静态网站 - 部署: 将构建结果上传到 GitHub Pages
如果构建失败:
- 查看 Actions 日志,找出错误信息
- 确保 Gemfile 中包含了所有必要的插件
- 确保 _config.yml 配置正确
如果某些页面未生成:
- 检查页面的 Front Matter 是否包含
lang属性 - 检查 permalink 配置是否正确(不应包含语言前缀)
- 检查文件路径是否正确
错误信息:
Your bundle is locked to nokogiri (1.19.0-x86_64-linux) from rubygems repository
https://mirrors.aliyun.com/rubygems/ or installed locally, but that version can
no longer be found in that source.
解决方案:
在本地删除并重新生成 Gemfile.lock:
# 删除 Gemfile.lock
rm Gemfile.lock
# 重新生成
bundle install
# 提交更改
git add Gemfile.lock
git commit -m "Update Gemfile.lock to fix nokogiri dependency"
git push origin main问题描述:GitHub Pages 默认构建和 GitHub Actions 同时运行,导致冲突。
解决方案:
- 打开 GitHub 仓库页面
- 点击 Settings > Pages
- 在 Build and deployment 部分:
- Source: 选择 "GitHub Actions"
- 这会禁用默认的 Jekyll 构建
- 保存设置
解决方案:
检查 .github/workflows/jekyll.yml 中的 Ruby 版本是否与本地一致,必要时更新:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0.2' # 或 '3.2',根据你的本地版本本项目基于 Jekyll 框架开发,Jekyll 采用 MIT 许可证。 原始版权信息如下:
Copyright (c) 2008-present Tom Preston-Werner and Jekyll contributors