Hexo搭建Github静态博客

Hexo搭建Github静态博客

1. 安装Git

Git官方下载地址:https://git-scm.com/download/

2. 安装node.js

node.js下载地址http://nodejs.org/download/
安装时直接保持默认配置即可。

3. 配置Github

3.1 建立Repository

建立与你用户名对应的仓库,仓库名必须为【your_user_name.github.io】

3.2 配置SSH-Key

4. 安装Hexo

4.1 Installation

打开Git命令行,执行如下命令

$ npm install -g hexo

4.2 Quick Start

1.Setup your blog

在电脑中建立一个名字叫「Hexo」的文件夹(比如我建在了D:\Hexo),然后在此文件夹中右键打开Git Bash。执行下面的命令

$ hexo init
[info] Copying data
[info] You are almost done! Don't forget to run npm install before you start b
logging with Hexo!

Hexo随后会自动在目标文件夹建立网站所需要的文件。然后按照提示,运行 npm install(在 /D/Hexo下)
npm install

会在D:\Hexo目录中安装 node_modules。

####2. Start the server ####
运行下面的命令(在 /D/Hexo下)

$ hexo server
[info] Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

表明Hexo Server已经启动了,在浏览器中打开 http://localhost:4000/,这时可以看到Hexo已为你生成了一篇blog。

你可以按Ctrl+C 停止Server。

3. Create a new post

新打开一个git bash命令行窗口,cd到/D/Hexo下,执行下面的命令

$ hexo new "My New Post"
[info] File created at d:\Hexo\source\_posts\My-New-Post.md

刷新http://localhost:4000/,可以发现已生成了一篇新文章 “My New Post”。

Note

有一个问题,发现 “My New Post” 被发了2遍,在Hexo server所在的git bash窗口也能看到create了2次。

$ hexo server
[info] Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
[create] d:\Hexo\source\_posts\My-New-Post.md
[create] d:\Hexo\source\_posts\My-New-Post.md

经验证,在hexo new “My New Post” 时,如果按Ctrl+C将hexo server停掉,就不会出现发2次的问题了。

所以,在hexo new文章时,需要stop server。

4. Generate static files

执行下面的命令,将markdown文件生成静态网页。

$ hexo generate

该命令执行完后,会在 D:\Hexo\public\ 目录下生成一系列html,css等文件。

####5. 编辑文章 ####
hexo new “My New Post”会在D:\Hexo\source_posts目录下生成一个markdown文件:My-New-Post.md

可以使用一个支持markdown语法的编辑器(比如 Sublime Text 2)来编辑该文件。

6. 部署到Github

部署到Github前需要配置_config.yml文件,首先找到下面的内容

# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
 type:

然后将它们修改为

# Deployment
## Docs: http://hexo.io/docs/deployment.html
deploy:
  type: github
  repository: git@github.com:zhchnchn/zhchnchn.github.io.git
  branch: master

7.测试

当部署完成后,在浏览器中打开http://codingmaster1.github.io/(https://codingmaster1.github.io/) ,正常显示网页,表明部署成功。

8.总结:部署步骤

每次部署的步骤,可按以下三步来进行。

hexo clean
hexo generate
hexo deploy

##References ##
【1】Windows下Git安装指南(http://www.cnblogs.com/zhcncn/p/3787849.html)

【2】Hexo (https://github.com/hexojs/hexo)

【3】hexo你的博客(http://ibruce.info/2013/11/22/hexo-your-blog/)

【4】Hexo All Themes(https://github.com/hexojs/hexo/wiki/Themes)

【5】Pacman主题介绍(http://yangjian.me/pacman/hello/introducing-pacman-theme/)

【6】hexo添加404页面(http://ruocaiwu.github.io/2014/08/14/hexo%E6%B7%BB%E5%8A%A0404%E9%A1%B5%E9%9D%A2/)

【7】如何搭建一个独立博客——简明Github Pages与Hexo教程(http://cnfeat.com/2014/05/10/2014-05-11-how-to-build-a-blog/)

【8】如何向google提交sitemap(详细)(http://fionat.github.io/blog/2013/10/23/sitemap/)

【9】GitHub Ribbons(https://github.com/blog/273-github-ribbons)

Austin wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!