Nodejs | 使用Hexo在Github上搭建博客

一、简介

Hexo 是一个基于 Node.js 的博客框架,采用 Markdown 语法编写博客内容,作为静态博客来说,比起Octopress,生成文章速度给力多了。好吧,其实我也还没用过Octopress,但是有更好的替代品为啥不用呢^^

二、安装

安装Hexo还是挺简单的,但是前提还是有以下这些环境才行
Git

$ sudo apt-get install git-core
# yum install git-core

Node.js

# curl https://raw.github.com/creationix/nvm/master/install.sh | sh
# nvm install 0.10

Hexo

# npm install -g hexo

三、使用

初始化hexo到blog

# hexo init blog
[info] Creating file: source/_posts/hello-world.md
[info] Creating file: package.json
[info] Creating file: .gitignore
...

新建文章

# hexo new "Hello World"
[info] File created at /root/clavinli/blog/source/_posts/hello-world.md

生成文章

# hexo generate
[info] Files loaded in 0.547s
[create] Public: archives/index.html
[create] Public: archives/2013/index.html
...

使用自带的server预览

# hexo server

发布到github

# hexo deploy
[info] Start deploying: github
[info] Clearing .deploy folder...
[info] Copying files from public folder...
...

四、部署到Github

首先需要去 Github 注册个账号,过程不表
nodejs-hexo-1.png

创建repository
在自己的Github主页右下角,创建一个新的repository。比如我的Github账号是clavinli,那么我创建的repository名字应该是clavinli.github.io
nodejs-hexo-2.png

部署
编辑_config.yml,把下面的clavinli换成你自己的账号名

deploy:
type: github
repository: https://github.com/clavinli/clavinli.github.io.git
branch: master

执行下列命令即可完成部署

# hexo generate
# hexo deploy

备注

每次修改完文件后,需要先hexo generate下再hexo deploy才能上传到Github

OK,到此为止,一个基于Github Page的个人博客就搭建完成了。