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

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

Creating a GitHub Pages site with Jekyll

You can use Jekyll to create a GitHub Pages site in a new or existing repository.

People with admin permissions for a repository can create a GitHub Pages site with Jekyll.

GitHub Pages 适用于具有 GitHub Free 和组织的 GitHub Free 的公共仓库,以及具有 GitHub Pro、GitHub Team、GitHub Enterprise Cloud 和 GitHub Enterprise Server 的公共和私有仓库。

本文内容

此文档对您有帮助吗?

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。

Prerequisites

Before you can use Jekyll to create a GitHub Pages site, you must install Jekyll and Git. For more information, see Installation in the Jekyll documentation and "Set up Git."

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

  1. 安装 Ruby。 更多信息请参阅 Ruby 文档中的“安装 Ruby”。
  2. 安装 Bundler。 更多信息请参阅“Bundler”。

提示:如果您在尝试使用 Bundler 安装 Jekyll 时看到 Ruby 错误,您可能需要使用包管理器(例如 RVMHomebrew)来管理您的 Ruby 安装。 更多信息请参阅 Jekyll 文档中的“故障排除”。

Creating a repository for your site

如果站点是一个独立的项目,您可以创建新仓库来存储站点源代码。 If your site is associated with an existing project, you can add the source code for your site to a gh-pages branch or a docs folder on the master branch in that project's repository. For example, if you're creating a site to publish documentation for a project that's already on GitHub Enterprise, you may want to store the source code for the site in the same repository as the project.

如果要在现有仓库中创建站点,请跳至“创建站点”一节。

Warning: If your site administrator has enabled Public Pages, GitHub Pages sites are publicly available on the internet, even if the repository for the site is private. If you have sensitive data in your site's repository, you may want to remove it before publishing. For more information, see "Configuring GitHub Pages on your appliance" and "About repository visibility."

  1. 在任何页面的右上角,使用 下拉菜单选择 New repository(新建仓库)
    带有创建新仓库选项的下拉菜单
  2. 使用 Owner(所有者)下拉菜单选择你想要拥有仓库的帐户。
    所有者下拉菜单
  3. 输入仓库的名称和说明(可选)。 如果您创建的是用户或组织站点,仓库名称必须为 <user>.github.io<organization>.github.io。 更多信息请参阅“关于 GitHub Pages”。
    创建仓库字段
  4. 选择仓库可见性。 更多信息请参阅“关于仓库可见性”。
    选择仓库可见性的单选按钮

Creating your site

必须先在 GitHub Enterprise 上有站点的仓库,然后才可创建站点。 如果未在现有仓库中创建站点,请参阅“为站点创建仓库”。

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

  2. If you don't already have a local copy of your repository, navigate to the location where you want to store your site's source files, replacing PARENT-FOLDER with the folder you want to contain the folder for your repository.

    $ cd PARENT-FOLDER
  3. If you haven't already, initialize a local Git repository, replacing REPOSITORY-NAME with the name of your repository.

    $ git init REPOSITORY-NAME
    > Initialized empty Git repository in /Users/octocat/my-site/.git/
    # Creates a new folder on your computer, initialized as a Git repository
  4. Change directories to the repository.

    $ cd REPOSITORY-NAME
    # Changes the working directory
  5. If you're creating a project site, decide which publishing source you want to use. If you're creating a user or organization site, you must store your site's source code on the master branch. For more information, see "About GitHub Pages."

  6. 导航到站点的发布来源。 有关发布源的更多信息,请参阅“关于 GitHub Pages”。 For example, if you chose to publish your site from the docs folder on the default branch, create and change directories to the docs folder.

    $ mkdir docs
    # Creates a new folder called docs
    $ cd docs

    If you chose to publish your site from the gh-pages branch, create and checkout the gh-pages branch.

    $ git checkout --orphan gh-pages
    # Creates a new branch, with no history or contents, called gh-pages and switches to the gh-pages branch
  7. To create a new Jekyll site, use the jekyll new command, replacing VERSION with the current dependency version for Jekyll. For more information, see "Dependency versions" on the GitHub Pages site.

    • If you installed Bundler:
      $ bundle exec jekyll VERSION new .
      # Creates a Jekyll site in the current directory
    • If you don't have Bundler installed:
      $ jekyll VERSION new .
      # Creates a Jekyll site in the current directory
  8. Open the Gemfile that was created and follow the instructions in the Gemfile's comments to use GitHub Pages.

    Instructions for updating Gemfile

  9. Update the gem "github-pages" line so that the line looks like this, replacing VERSION with the current dependency version for github-pages. For more information, see "Dependency versions" on the GitHub Pages site.

    gem "github-pages", "~> VERSION", group: :jekyll_plugins
  10. Save and close the Gemfile.

  11. Optionally, test your site locally. For more information, see "Testing your GitHub Pages site locally with Jekyll."

  12. Add your GitHub Enterprise repository as a remote, replacing HOSTNAME with your appliance's hostname, USER with the account that owns the repository, and REPOSITORY with the name of the repository.

    $ git remote add origin https://HOSTNAME/USER/REPOSITORY.git
    
  13. Push the repository to GitHub Enterprise, replacing BRANCH with the name of the branch you're working on.

    $ git push -u origin BRANCH
  14. 配置发布源。 更多信息请参阅“配置 GitHub Pages 站点的发布来源”。

  15. 在 GitHub Enterprise 上,导航到站点的仓库。

  16. 在仓库名称下,单击 Settings(设置)

    仓库设置按钮

  17. 要查看您已发布的站点,请在“GitHub Pages”下点击您的站点 URL。

    已发布站点的 URL

    注:对站点的更改在推送到 GitHub Enterprise 后,最长可能需要 20 分钟才会发布。 如果一小时后仍然在浏览器中看不到您的更改,请参阅“关于 GitHub Pages 站点的 Jekyll 构建错误”。

Note: If your site's source files are located in the default publishing source—master for user and organization sites or gh-pages for project sites—but your site has not published automatically, make sure someone with admin permissions and a verified email address has pushed to the publishing source.

Next steps

To add a new page or post to your site, see "Adding content to your GitHub Pages site using Jekyll."

您可以将 Jekyll 主题添加到 GitHub Pages 站点,以自定义站点的外观。 For more information, see "Adding a theme to your GitHub Pages site using Jekyll."

此文档对您有帮助吗?

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。