Setup blogs on GitHub Pages

环境搭建

安装Git

1
$ brew install git

安装Node.js

node官网安装最新版本的node.js

安装Hexo

切换到工作目录:

1
2
3
4
5
$ mkdir GitHubPages
$ cd GitHubPages
$ npm install -g hexo --verbose
$ hexo init
$ npm install --verbose

可能会因为网络问题安装失败,失败则需要进行重试。

测试Hexo

hexo常用命令:

- hexo n “blog’s name” 创建文章
- hexo g 生成文章
- hexo s 开启服务
- hexo d 部署文章
- hexo clean 清空项目

这是开启服务进行测试:

1
2
$ hexo s
INFO Hexo is running at http://0.0.0.0:4000/. Press Ctrl+C to stop.

在浏览器中输入对应的网址进行访问,访问是需要关闭防火墙、VPN、SS等。

更换主题

找到合适的Hexo主题后通过git下载,比如使用nexT主题:

1
$ git clone https://github.com/iissnan/hexo-theme-next.git themes/next

然后修改.yml配置文件,将theme字段的值改为next,重新开启服务测试效果。

编写Markdown

Markdown基本语法

#一级标题
##二级标题
###三级标题
####四级标题
#####五级标题
######六级标题

- 无序列表
- 无序列表
- 无序列表

1. 有序列表
2. 有序列表
3. 有序列表

- 嵌套列表
 + 嵌套列表
 + 嵌套列表
  * 嵌套列表
  * 嵌套列表

文字超链
[zhange](http://zhan-ge.github.io "zhange's blog")

图片超链
![GitHub Mark](http://github.global.ssl.fastly.net/images/modules/logos_page/GitHub-Mark.png "GitHub Mark")

索引超链
[zhange][1]
![GitHub Octocat][2]

[1]:https://github.com/zhan-ge
[2]:http://github.global.ssl.fastly.net/images/modules/logos_page/Octocat.png

自动连接
<http://ibruce.info>
<bu.ru@qq.com>

代码:四个空格或Tab
    import sys
    print "Hello man!"

注释
<!-- 注释 -->

表格
<table border="1">
    <tr>
        <td>row 1, cell 1</td>
        <td>row 1, cell 2</td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>row 2, cell 2</td>
    </tr>
</table>

文字添加颜色
<font color="#ff0000">红色
<font color="#ff8000">橙色
<font color="#ffff00">黄色
<font color="#00ff00">绿色
<font color="#0080ff">蓝色
<font color="#0000a0">靛色
<font color="#8000ff">紫色
<font color="#000000">黑色
<font color="#c0c0c0">灰色

Markdown详细语法请参考中文地址

部署

修改.yml配置文件中的Deployment部分:

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

配置完成后打开终端:

1
2
$ hexo g
$ hexo d

浏览器中输入”username.github.io”测试效果。