在Github上利用Hexo创建博客

在Github上利用Hexo创建博客

Hexo是一款基于Nodejs的,快速、简单且功能强大的博客框架。支持多线程,支持markdown编写文章,可以方便的生成静态网页托管在github上。

Install Hexo

步骤:

1 安装 Git

下载并安装 msysgit

2 安装 node.js 和 npm

下载并安装 nodejs

3 安装 Hexo

1
$ npm install hexo-cli -g

4 创建Hexo文件夹

创建一个文件夹用于编写本地博客,如(E:\hexo)。

在此文件夹中输入以下命令进行初始化:

1
$ hexo init

5 安装依赖包

1
$ npm install

至此,我们就安装好Hexo了,并且可以开始撰写本地博客了。

Using Hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Usage: hexo <command>

Commands:
clean Removed generated files and cache.
config Get or set configurations.
deploy Deploy your website.
generate Generate static files.
help Get help on a command.
init Create a new Hexo folder.
list List the information of the site
migrate Migrate your site from other system to Hexo.
new Create a new post.
publish Moves a draft post from _drafts to _posts folder.
render Render files with renderer plugins.
server Start the server.
version Display version information.

常用命令:

创建一篇新的博客

1
2
3
hexo new
or
hexo n

生成静态博客文件

1
2
3
hexo generate
or
hexo g

启动本地服务

1
2
3
hexo server
or
hexo s

执行可以在浏览器中输入localhost:4000 预览博客。

Deploy

部署之前先要配置一下Hexo。

1 安装hexo-deployer-git

1
$ npm install hexo-deployer-git --save

2 在目录 E:\hexo 下,编辑 _config.yml(将xyz换成你自己的github用户名):

1
2
3
4
deploy:
type: git
repository: https://github.com/xyz/xyz.github.io.git
branch: master

执行下列指令即可完成部署。

1
2
hexo generate
hexo deploy

中途会提示输入GitHub账号和密码,正常输入即可。

Tips

  1. 每次修改本地文件后,需要执行 hexo generate 才能生成新的博客文件。
  2. 所有hexo命令都要在 hexo 文件目录下执行。
  3. 发布后GitHub会有一定的延时