之前写了一篇HEXO搭建个人博客的教程获得了很好评,尤其是在简书上目前已经累积了10W+的阅读量了,也有好心的读者主动给我打赏,在此感谢。
如果你看过我的文章会发现我现在的博客样式跟之前是有很大的区别的,之前我也是使用 HEXO 搭建的博客,后来发现使用 HEXO 在多台电脑上发布博客,操作起来并不是那么方便,果断就转到了 Jekyll 上,接下来我会讲如何使用 Jekyll 搭建博客,博客模板效果。
介绍
Jekyll 是一个简单的博客形态的静态站点生产机器。它有一个模版目录,其中包含原始文本格式的文档,通过 Markdown (或者 Textile) 以及 Liquid 转化成一个完整的可发布的静态网站,你可以发布在任何你喜爱的服务器上。Jekyll 也可以运行在 GitHub Page 上,也就是说,你可以使用 GitHub 的服务来搭建你的项目页面、博客或者网站,而且是完全免费的
使用 Jekyll 搭建博客之前要确认下本机环境,Git 环境(用于部署到远端)、Ruby 环境(Jekyll 是基于 Ruby 开发的)、包管理器 RubyGems
如果你是 Mac 用户,你就需要安装 Xcode 和 Command-Line Tools了。下载方式 Preferences → Downloads → Components。
Jekyll 是一个免费的简单静态网页生成工具,可以配合第三方服务例如: Disqus(评论)、多说(评论) 以及分享 等等扩展功能,Jekyll 可以直接部署在 Github(国外) 或 Coding(国内) 上,可以绑定自己的域名。Jekyll中文文档、Jekyll英文文档、Jekyll主题列表。
Jekyll 环境配置
安装 jekyll
1 | $ gem install jekyll |
$ cd myBlog
1 |
|
$ jekyll serve
1 |
|
.
├── _config.yml
├── _includes
| ├── footer.html
| └── header.html
├── _layouts
| ├── default.html
| ├── post.html
| └── page.html
├── _posts
| └── 2016-10-08-welcome-to-jekyll.markdown
├── _sass
| ├── _base.scss
| ├── _layout.scss
| └── _syntax-highlighting.scss
├── about.md
├── css
| └── main.scss
├── feed.xml
└── index.html
1 |
|
layout: post
title: “Welcome to Jekyll!”
date: 2016-10-16 11:29:08 +0800
categories: jekyll update
正文…
1 |
|
$ jekyll server
1 |
|
/Users/xxxxxxxx/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- bundler (LoadError) from /Users/xxxxxxxx/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in
require’
from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/gems/jekyll-3.3.0/lib/jekyll/plugin_manager.rb:34:in require_from_bundler' from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/gems/jekyll-3.3.0/exe/jekyll:9:in
<top (required)>’
from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/bin/jekyll:23:in load' from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/bin/jekyll:23:in
from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in eval' from /Users/xxxxxxxx/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in
1 |
|
$ gem install bundler
1 |
|
Fetching: bundler-1.13.5.gem (100%)
Successfully installed bundler-1.13.5
Parsing documentation for bundler-1.13.5
Installing ri documentation for bundler-1.13.5
Done installing documentation for bundler after 5 seconds
1 gem installed
1 |
|
Could not find proper version of jekyll (3.1.1) in any of the sources
Run bundle install
to install missing gems.
1 |
|
$ bundle install
1 |
|
$ gem sources –remove https://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
$ gem sources -l
* CURRENT SOURCES *
1 |
|
Fetching gem metadata from https://rubygems.org/………..
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
。。。
Installing jekyll-watch 1.3.1
Installing jekyll 3.1.1
Bundle complete! 3 Gemfile dependencies, 17 gems now installed.
Use bundle show [gemname]
to see where a bundled gem is installed.
1 |
|
$ jekyll server
1 |
|
Configuration file: /Users/tendcloud-Caroline/Desktop/leopardpan.github.io/_config.yml
Dependency Error: Yikes! It looks like you don’t have jekyll-sitemap or one of its dependencies installed. In order to use Jekyll as currently configured, you’ll need to install this gem. The full error message from Ruby is: ‘cannot load such file – jekyll-sitemap’ If you run into trouble, you can find helpful resources at http://jekyllrb.com/help/!
jekyll 3.1.1 | Error: jekyll-sitemap
1 | 表示 当前的 jekyll 版本是 3.1.1 ,无法使用 jekyll-sitemap |
$ jekyll server
1 | 提示 |
Configuration file: /Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github/_config.yml
Source: /Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github
Destination: /Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github/_site
Incremental build: disabled. Enable with –incremental
Generating…
done in 0.901 seconds.
Auto-regeneration: enabled for ‘/Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github’
Configuration file: /Users/baixinpan/Desktop/OpenSource/Mine/Page-Blog/leopardpan.github.io-github/_config.yml
Server address: http://127.0.0.1:4000/
Server running… press ctrl-c to stop.
表示本地服务部署成功。
在浏览器输入 [127.0.0.1:4000](127.0.0.1:4000) , 就可以看到[leopardpan.cn](http://leopardpan.cn)博客效果了。
### 修改成你自己的博客
>* 如果你想使用我的模板请把 _posts/ 目录下的文章都去掉。
>* 修改 _config.yml 文件里面的内容为你自己的。
然后使用 git push 到你自己的仓库里面去,检查你远端仓库,在浏览器输入 username.github.io 就会发现,你有一个漂亮的主题模板了。
### 为什么要是用 Jekyll
使用了 Jekyll 你会发现如果你想使用多台电脑发博客都很方便,只要把远端 github 仓库里的博客 clone 下来,写文章后再提交就可以了,Hexo 由于远端提交的是静态网页,所有无法直接写 Markdown 的文章。如果你想看 Hexo 搭建博客,可以看看我的另一篇[HEXO搭建个人博客](http://leopardpan.cn/2015/08/HEXO%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/)的教程。
如果你在搭建博客遇到问题,可以在[原文博客](http://leopardpan.cn/2016/10/jekyll_tutorials1/)的评论里给我提问。
后面会继续介绍,在我的博客基础上,如何修改成你自己喜欢的 Style,欢迎继续关注我博客的更新。
### Q&A
> 问题:最近很多朋友使用我的模板报警告:The CNAME `leopardpan.cn` is already taken
> 解决:把CNAME里面的baixin.io修改成你自己的域名,如果你暂时没有域名,CNAME里面就什么都不用谢。(之前没人反馈过这个问题,应该是github page最近才最的限制。)