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

Adding content to your GitHub Pages site using Jekyll

You can add a new page or post to your Jekyll site on GitHub Pages.

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. For more information, see "GitHub's products."

本文内容

People with write permissions for a repository can add content to a GitHub Pages site using Jekyll.

About content in Jekyll sites

Before you can add content to a Jekyll site on GitHub Pages, you must create a Jekyll site. For more information, see "Creating a GitHub Pages site with Jekyll."

The main types of content for Jekyll sites are pages and posts. A page is for standalone content that isn't associated with a specific date, such as an "About" page. The default Jekyll site contains a file called about.md, which renders as a page on your site at YOUR-SITE-URL/about. You can edit the contents of that file to personalize your "About" page, and you can use the "About" page as a template to create new pages. For more information, see "Pages" in the Jekyll documentation.

A post is a blog post. The default Jekyll site contains a directory named _posts that contains a default post file. You can edit the contents of that post, and you can use the default post as a template to create new posts. For more information, see "Posts" in the Jekyll documentation.

Your theme includes default layouts, includes, and stylesheets that will automatically be applied to new pages and posts on your site, but you can override any of these defaults. 更多信息请参阅“关于 GitHub Pages 和 Jekyll”。

To set variables and metadata, such as a title and layout, for a page or post on your site, you can add YAML front matter to the top of any Markdown or HTML file. For more information, see "Front Matter" in the Jekyll documentation.

Changes to your site are published automatically when the changes are merged into your site's publishing source. If you want to preview your changes first, you can make the changes locally instead of on GitHub. Then, test your site locally. For more information, see "Testing your GitHub Pages site locally with Jekyll."

Adding a new page to your site

  1. On GitHub, navigate to your site's repository.

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

  3. In the root of your publishing source, create a new file for your page called PAGE-NAME.md, replacing PAGE-NAME with a meaningful filename for the page.

  4. Add the following YAML frontmatter to the top of the file, replacing PAGE TITLE with the page's title and URL-PATH with a path you want for the page's URL. For example, if the base URL of your site is https://octocat.github.io and your URL-PATH is /about/contact/, your page will be located at https://octocat.github.io/about/contact.

    layout: page
    title: "PAGE TITLE"
    permalink: /URL-PATH/
  5. Below the frontmatter, add content for your page.

  6. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file. You can attribute the commit to more than one author in the commit message. For more information, see "Creating a commit with multiple co-authors."

    有关更改的提交消息

  7. 以下是提交消息字段,请单击电子邮件地址下拉菜单并选择 Git 作者电子邮件地址。 只有经过验证的电子邮件地址才会出现在此下拉菜单中。 如果您启用了电子邮件地址隐私保护,则 <username>@users.noreply.github.com 为默认的提交作者电子邮件地址。 更多信息请参阅“设置提交电子邮件地址”。

    Choose commit email addresses

  8. 在提交消息字段下面,确定是要将提交添加到当前分支还是新分支。 If your current branch is master, you should choose to create a new branch for your commit and then create a pull request. For more information, see "Creating a new pull request."

    提交分支选项

  9. 单击 Propose file change(提议文件更改)

    Propose file change button

Adding a new post to your site

  1. On GitHub, navigate to your site's repository.

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

  3. Navigate to the _posts directory.

  4. Create a new file called YYYY-MM-DD-NAME-OF-POST.md, replacing YYYY-MM-DD with the date of your post and NAME-OF-POST with the name of your post.

  5. Add the following YAML frontmatter to the top of the file, replacing POST TITLE with the post's title, YYYY-MM-DD hh:mm:ss -0000 with the date and time for the post, and CATEGORY-1 and CATEGORY-2 with as many categories you want for your post.

    layout: page
    title: "POST TITLE"
    date: YYYY-MM-DD hh:mm:ss -0000
    categories: CATEGORY-1 CATEGORY-2
  6. Below the frontmatter, add content for your post.

  7. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file. You can attribute the commit to more than one author in the commit message. For more information, see "Creating a commit with multiple co-authors."

    有关更改的提交消息

  8. 以下是提交消息字段,请单击电子邮件地址下拉菜单并选择 Git 作者电子邮件地址。 只有经过验证的电子邮件地址才会出现在此下拉菜单中。 如果您启用了电子邮件地址隐私保护,则 <username>@users.noreply.github.com 为默认的提交作者电子邮件地址。 更多信息请参阅“设置提交电子邮件地址”。

    Choose commit email addresses

  9. 在提交消息字段下面,确定是要将提交添加到当前分支还是新分支。 If your current branch is master, you should choose to create a new branch for your commit and then create a pull request. For more information, see "Creating a new pull request."

    提交分支选项

  10. 单击 Propose file change(提议文件更改)

    Propose file change button

后续步骤

You can add a Jekyll theme to your GitHub Pages site to customize the look and feel of your site. For more information, see "Adding a theme to your GitHub Pages site using Jekyll."

问问别人

找不到要找的内容?

联系我们