使用jekyll搭建github pages博客

起因

github pages是搭建个人博客的一个优秀平台,由于我之前将博客建在了CSDN,写了含有”翻墙”之类敏感关键词的博客而未审核通过(天朝你懂的),就怒而决定选择新的博客平台,恰好发掘到了github pages。

优点介绍

我个人在之前查找了很多资料,看了一些博客内容(比如阮一峰的博客),认为github pages有很多优点,比如:

  • github pages无需自己购买主机,直接使用github上的免费空间即可
  • github pages的可定制化更强,可以使用多种工具和模板,我用的是其官方推荐的jekyll,套用了一个简洁的模板
  • github pages支持Markdown,而Markdown绝对是书写神器,它让在写文档时进行结构控制和代码高亮变得异常轻松
  • 至于有人说用github pages建站麻烦,其实也不过如此,无非几个步骤而已

搭建过程

至于搭建过程,用Google可以搜索到很多教程,我这里就挑重要的说:

  1. 推荐使用Linux(如果你是土豪,用Mac),因为在windows上搞会容易出很多很多问题
  2. 推荐去github pages的官方主页,那里有用jekyll构建的完整教程,步骤详尽,而且有很多指向jekyll的链接,方便至极
  3. 安装Ruby,安装jekyll,也要安装个rake

使用

  • 要熟悉目录结构,配置文件_config.yml
  • 新增文章,可以使用rake post title="" date=""
  • 美化和代码高亮等可以用更改CSS解决,后者需要的python在Linux上本就安装好了,而在windows下有很多问题,这也是推荐Linux的原因

结语

哈哈,可以享受github pages了。

备注

这是我_config.yml,尤其要注意几个路径,一定不要错了。这样就可以正确发布到github和引用图片了!

# This is the default format. 
# For more see: http://jekyllrb.com/docs/permalinks/
permalink: /:categories/:year/:month/:day/:title

exclude: [".rvmrc", ".rbenv-version", "README.md", "Rakefile", "changelog.md"]
highlighter: pygments
markdown: redcarpet
redcarpet:
extensions:
- hard_wrap
- no_intra_emphasis
- autolink
- strikethrough
- fenced_code_blocks
# Themes are encouraged to use these universal variables
# so be sure to set them if your theme uses them.
#
title : 郑明培的博客
tagline: Site Tagline
author :
name : Mingpei Zheng
email : yueyawanbian@gmail.com
github : Zhengmingpei

# The production_url is only used when full-domain names are needed
# such as sitemap.txt
# Most places will/should use BASE_PATH to make the urls
#
# If you have set a CNAME (pages.github.com) set your custom domain here.
# Else if you are pushing to username.github.io, replace with your username.
# Finally if you are pushing to a GitHub project page, include the project name at the end.
#
production_url : http://Zhengmingpei.github.io

# All Jekyll-Bootstrap specific configurations are namespaced into this hash
#
JB :
version : 0.3.0

# All links will be namespaced by BASE_PATH if defined.
# Links in your website should always be prefixed with {{BASE_PATH}}
# however this value will be dynamically changed depending on your deployment situation.
#
# CNAME (http://yourcustomdomain.com)
# DO NOT SET BASE_PATH
# (urls will be prefixed with "/" and work relatively)
#
# GitHub Pages (http://username.github.io)
# DO NOT SET BASE_PATH
# (urls will be prefixed with "/" and work relatively)
#
# GitHub Project Pages (http://username.github.io/project-name)
#
# A GitHub Project site exists in the `gh-pages` branch of one of your repositories.
# REQUIRED! Set BASE_PATH to: http://username.github.io/project-name
#
# CAUTION:
# - When in Localhost, your site will run from root "/" regardless of BASE_PATH
# - Only the following values are falsy: ["", null, false]
# - When setting BASE_PATH it must be a valid url.
# This means always setting the protocol (http|https) or prefixing with "/"
BASE_PATH : false

# By default, the asset_path is automatically defined relative to BASE_PATH plus the enabled theme.
# ex: [BASE_PATH]/assets/themes/[THEME-NAME]
#
# Override this by defining an absolute path to assets here.
# ex:
# http://s3.amazonaws.com/yoursite/themes/watermelon
# /assets
#
ASSET_PATH : false

# These paths are to the main pages Jekyll-Bootstrap ships with.
# Some JB helpers refer to these paths; change them here if needed.
#
archive_path: /archive.html
categories_path : /categories.html
tags_path : /tags.html
atom_path : /atom.xml
rss_path : /rss.xml

# Settings for comments helper
# Set 'provider' to the comment provider you want to use.
# Set 'provider' to false to turn commenting off globally.
#
comments :
provider : disqus
disqus :
short_name : jekyllbootstrap
livefyre :
site_id : 123
intensedebate :
account : 123abc
facebook :
appid : 123
num_posts: 5
width: 580
colorscheme: light

# Settings for analytics helper
# Set 'provider' to the analytics provider you want to use.
# Set 'provider' to false to turn analytics off globally.
#
analytics :
provider : google
google :
tracking_id : 'UA-123-12'
getclicky :
site_id :
mixpanel :
token : '_MIXPANEL_TOKEN_'
piwik :
baseURL : 'myserver.tld/piwik' # Piwik installation address (without protocol)
idsite : '1' # the id of the site on Piwik

# Settings for sharing helper.
# Sharing is for things like tweet, plusone, like, reddit buttons etc.
# Set 'provider' to the sharing provider you want to use.
# Set 'provider' to false to turn sharing off globally.
#
sharing :
provider : false

# Settings for all other include helpers can be defined by creating
# a hash with key named for the given helper. ex:
#
# pages_list :
# provider : "custom"
#
# Setting any helper's provider to 'custom' will bypass the helper code
# and include your custom code. Your custom file must be defined at:
# ./_includes/custom/[HELPER]
# where [HELPER] is the name of the helper you are overriding.

就到这里。