我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

此版本的 GitHub Enterprise 将停止服务 此版本的 GitHub Enterprise 已停止服务 2020-01-22. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持

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 is available in public repositories with GitHub Free, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and 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:

我们建议使用 Bundler 安装和运行 Jekyll。 Bundler 可管理 Ruby gem 依赖项,减少 Jekyll 构建错误和阻止环境相关的漏洞。 To install Bundler:

  1. Install Ruby. For more information, see "Installing Ruby" in the Ruby documentation.
  2. Install Bundler. For more information, see "Bundler."

提示:如果您在尝试使用 Bundler 安装 Jekyll 时看到 Ruby 错误,您可能需要使用包管理器(例如 RVMHomebrew)来管理您的 Ruby 安装。 For more information, see "Troubleshooting" in the Jekyll documentation.

本地构建网站

  1. 打开 Terminal(终端)Terminal(终端)Git Bash终端

  2. Navigate to the publishing source for your site. 有关发布源的更多信息,请参阅“关于 GitHub Pages”。

  3. 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.
  4. 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.

  1. 打开 Terminal(终端)Terminal(终端)Git Bash终端

  2. Update the github-pages gem.

    • If you installed Bundler, run bundle update github-pages.
    • 如果未安装 Bundler,则运行 gem update github-pages.

延伸阅读

问问别人

找不到要找的内容?

联系我们