Using Jekyll with Pages——使用Jekyll框架

In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog-aware static site generator. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers some other advanced templating features.

为了支持HTML内容,GitHub Pages支持了Jekyll框架,Jekyll是一个简单的博客类静态网站生成器。Jekyll能够简单地在各个页面中使用全局的headers和footers。同时Jekyll也能提供一些其他的模版特性。

Using Jekyll——使用Jekyll

Every GitHub Page is run through Jekyll when you push content to a specially named branch within your repository. For User Pages, use the master branch in your username.github.io repository. For Project Pages, use the gh-pages branch in your project's repository. Because a normal HTML site is also a valid Jekyll site, you don't have to do anything special to keep your standard HTML files unchanged. Jekyll has thorough documentation that covers its features and usage. Simply start committing Jekyll formatted files and you'll be using Jekyll in no time.

当你向一个特殊命名的远程仓库推送内容后,GitHub Page就能够通过Jekyll来运行。对于用户页面,可以在名为username.github.io的仓库中设置master分支。对于项目页面,在项目仓库中设置gh-pages分支。因为一个普通的HTML网页也是一个Jekyll框架网页,所以你无需对你的标准HTML文件做任何改动。Jekyll有专门描述其特性和使用方法的文档。你可以轻轻松松使用Jekyll框架来实现你的网站。

Installing Jekyll——安装Jekyll

We highly recommend installing Jekyll on your computer to preview your site and help diagnose troubled builds before publishing your site on GitHub Pages.

Luckily, installing Jekyll on your computer, and ensuring your computer most closely matches the GitHub Pages settings is easy, thanks to the GitHub Pages Gem and our dependency versions page. To install Jekyll, you'll need a few things:

我们强烈推荐你在你的电脑上安装Jekyll来预览你的网站,同时这也能帮助你在GitHub Pages上发布网站之前,诊断因为部署失败而引发的错误。非常幸运地,在电脑上安装Jekyll和相关设置非常的简单易懂。安装Jekyll的步骤如下:

  • Ruby - Jekyll requires the Ruby language. If you have a Mac, you've most likely already got Ruby. If you open up the Terminal application, and run the command ruby --version you can confirm this. Your Ruby version should begin with 1.9.3 or 2.0.0. If you've got that, you're all set. Skip to step #2. Otherwise, follow these instructions to install Ruby.

  • Bundler - Bundler is a package manager that makes versioning Ruby software like Jekyll a lot easier if you're going to be building GitHub Pages sites locally. If you don't already have Bundler installed, you can install it by running the command gem install bundler.

  • Jekyll - The main event. You'll want to create a file in your site's repository called Gemfile and add the line gem 'github-pages'. After that, simply run the command, bundle install and you're good to go. If you decided to skip step #2, you can still install Jekyll with the command gem install github-pages, but you may run into trouble down the line. Here’s an example of a Gemfile you can use (placed in the root directory of your repository):

source 'https://rubygems.org'
gem 'github-pages'
  • Ruby: Jekyll要求电脑上已经安装了Ruby语言。如果你使用的是Mac,那么你的电脑中已经预装了Ruby。你可以打开终端输入ruby --version来查看Ruby的版本信息。Ruby的版本号必须介于1.9.3到2.0.0之间。如果你已经确认这些信息都是正确的,那么第一步就已经完成了,接下来可以执行第二步。否则,按要求安装Ruby

  • Bundler: Bundler是一个Ruby应用的包管理软件。如果你没有安装Bundler,请在命令行中输入gem install bundler

  • Jekyll: 在你的网站仓库的根目录下创建一个名为Gemfile的文件,在文件中写下gem 'github-pages'。然后,在命令行中输入bundle install就会安装Jekyll和所有相关的依赖包。如果你跳过了第二步,你仍能够安装Jekyll,在命令行中输入gem install github-pages,但你可能会遇到一些问题,此时你要修改Gemfile文件。如下:

source 'https://rubygems.org'
gem 'github-pages'

Running Jekyll——运行Jekyll

To run Jekyll in a way that matches the GitHub Pages build server, run Jekyll with Bundler. Use the command bundle exec jekyll serve in the root of your repository (after switching to the gh-pages branch for project repositories), and your site should be available athttp://localhost:4000. For a full list of Jekyll commands, see the Jekyll documentation.

为了模拟GitHub Pages使用Jekyll部署服务器的过程,我们使用Bundler运行Jekyll。具体操作:在网页仓库根目录下命令行输入bundle exec jekyll serve(如果是项目仓库,需要切换到gh-pages分支)。然后你就可以在浏览器中访问http://localhost:4000来看到你在本地生成的网页。所有的Jekyll命令请见Jekyll文档

Keeping Jekyll up to date——更新Jekyll

Jekyll is an active open source project, and is updated frequently. As the GitHub Pages server is updated, the software on your computer may become out of date, resulting in your site appearing different locally from how it looks when published on GitHub. To keep Jekyll up to date, you can run the command bundle update (or if you opted out of step 2, run gem update github-pages).

Jekyll是一个非常活跃的开源项目,它更新得非常频繁。当GitHub Pages服务器更新后,你电脑上的Jekyll可能就过时了,这会导致你的网站在GitHub上显示的模样和在本地模拟的模样不同。所以,请保证你的Jekyll是最新版本,你可以在命令行中输入bundle update来更新Jekyll(如果你跳过了安装的第二步,请输入gem update github-pages)。

Configuring Jekyll——配置Jekyll

You can configure most Jekyll settings by creating a _config.yml file.

你可以通过创建和修改_config.yml文件来完成大部分的Jekyll设置。

Defaults——默认设置

The following defaults are set by GitHub, which you are free to override in your _config.yml file:

下面_config.yml文件中的默认设置是来自GitHub的,你可以自由地修改。

highlighter: pygments
github: [Repository metadata]

For the content of the repository metadata object, see repository metadata on GitHub Pages.

仓库内的元数据内容请见repository metadata on GitHub Pages

Configuration Overrides

We override the following _config.yml values, which you are unable to configure:

我们可以修改_config.yml文件中的值(一般不需要修改):

safe: true
lsi: false
source: your top-level directory

Keep in mind that if you change the source setting, your pages may not build correctly. GitHub Pages only considers source files in the top-level directory of a repository.

如果你更改了source设置,你的页面可能会部署失败。GitHub Pages只会考虑仓库中顶级目录下的source文件。

Frontmatter is required——格式

Jekyll requires that Markdown files have front-matter defined at the top of every file. Front-matter is just a set of metadata, delineated by three dashes:

Jekyll要求每一个Markdown文件在头部进行定义,主要是设置元数据。通过---与正文分隔。

---
title: This is my title
layout: post
---

Here is my page.

If you like, you can choose to omit front-matter from your file, but you'll still need to make the triple-dashes:

你可以省略你的头部定义,但你仍需要---来分隔。

---
---

Here is my page.

If your file is within the _posts directory, you can omit the dashes entirely.

For more information, check out the Jekyll docs.

如果你的文件在_posts目录下,你能够省略---。更多的信息请见Jekyll文档

Troubleshooting——解决问题

If your Jekyll site is not rendering properly after you push it to GitHub, it's useful to run Jekyll locally so you can see any parsing errors. In order to do this, you'll want to use the same versions of Jekyll and other dependencies that we use.

如果你推送commit到GitHub后,你的Jekyll网站没有正常显示,那么你可以在本地运行Jekyll来找到错误的原因。但前提是,你必须使用与GitHub Pages相同的Jekyll和依赖包版本

To ensure your local development environment is using the same version of Jekyll and its dependencies as GitHub Pages, you can periodically run the command gem update github-pages (or bundle update github-pages if using Bundler) once Jekyll is installed. For more information, see the GitHub Pages Gem repository.

为保证你的本地开发环境所使用的Jekyll和依赖包与GitHub Pages相同,你可以定期地在命令行中输入gem update github-pages(如果安装了Bundler,输入bundle update github-pages)。更多信息详见GitHub Pages Gem repository

If your page isn't building after you push to GitHub, see "Troubleshooting GitHub Pages build failures".

如果你的网页不能正常显示。请见"Troubleshooting GitHub Pages build failures"

If you are having issues with your Jekyll Pages, make sure you are not using categories that are named the same as another project, as this could cause path conflicts. For example: if you have a blog post named 'resume' in your User Page repository and a project named 'resume' with a gh-pages branch, they will conflict with each other.

如果你的Jekyll页面有问题,请确保没有重名的情况发生,否则会造成路径冲突。例如:在你的个人用户网站仓库中有一篇名为‘resume’的博文,同时恰好又有一个名为‘resume’的项目下有gh-pages分支。

Turning Jekyll off——关闭Jekyll

You can completely opt out of Jekyll processing by creating a file named .nojekyll in the root of your Page repository and pushing that file to GitHub. This should only be necessary if your site uses directories that begin with an underscore, as Jekyll sees these as special directories and does not copy them to the final destination.

如果你不想使用这个Jekyll页面,你可以在你的个人用户页面仓库的根目录下创建一个名为.nojekyll的文件,同时将这个改动推送到远程仓库。那么就可以隐藏这个网站了。

Contributing——贡献

If there's a feature you wish that Jekyll had, feel free to fork it and send a pull request. We're happy to accept user contributions.

如果你希望Jekyll有一些其他特性,请fork后pull request你的改动。我们很高兴能接受用户的贡献。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,847评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,208评论 1 292
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,587评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,942评论 0 205
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,332评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,587评论 1 218
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,853评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,568评论 0 198
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,273评论 1 242
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,542评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,033评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,373评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,031评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,073评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,830评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,628评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,537评论 2 269

推荐阅读更多精彩内容