文章版本: Enterprise Server 2.17
Testing your GitHub Pages site locally with Jekyll
You can build your GitHub Pages site locally to preview and test changes to your site.
GitHub Pages 适用于具有 GitHub Free 和组织的 GitHub Free 的公共仓库,以及具有 GitHub Pro、GitHub Team、GitHub Enterprise Cloud 和 GitHub Enterprise Server 的公共和私有仓库。
Anyone with read permissions for a repository can test a GitHub Pages site locally.
基本要求
Before you can use Jekyll to test a site, you must:
- Install Jekyll.
- Create a Jekyll site. For more information, see "Creating a GitHub Pages site with Jekyll."
我们建议使用 Bundler 安装和运行 Jekyll。 Bundler 可管理 Ruby gem 依赖项,减少 Jekyll 构建错误和阻止环境相关的漏洞。 要安装 Bundler:
本地构建网站
- 打开 Terminal(终端)Terminal(终端)Git Bash。
- 导航到站点的发布来源。 有关发布源的更多信息,请参阅“关于 GitHub Pages”。
- Run your Jekyll site locally.
$ bundle exec jekyll serve > Configuration file: /Users/octocat/my-site/_config.yml > Source: /Users/octocat/my-site > Destination: /Users/octocat/my-site/_site > Incremental build: disabled. Enable with --incremental > Generating... > done in 0.309 seconds. > Auto-regeneration: enabled for '/Users/octocat/my-site' > Configuration file: /Users/octocat/my-site/_config.yml > Server address: http://127.0.0.1:4000/ > Server running... press ctrl-c to stop.
- To preview your site, in your web browser, navigate to
http://localhost:4000
.
Updating the GitHub Pages gem
Jekyll is an active open source project that is updated frequently. If the github-pages
gem on your computer is out of date with the github-pages
gem on the GitHub Pages server, your site may look different when built locally than when published on GitHub Enterprise. To avoid this, regularly update the github-pages
gem on your computer.
- 打开 Terminal(终端)Terminal(终端)Git Bash。
- Update the
github-pages
gem.- If you installed Bundler, run
bundle update github-pages
. - 如果未安装 Bundler,则运行
gem update github-pages
.
- If you installed Bundler, run
延伸阅读
- GitHub Pages in the Jekyll documentation