Hexo 搭建博客

系统环境配置

1
2
Node.js
Git

安装Hexo

1
2
3
4
5
6
7
$ cd hexo
$ npm install hexo-cli -g
$ hexo into blog
$ cd blog
$ npm install
$ hexo g || hexo generate
$ hexo s || hexo server

Hexo 常用命令
hexo g 生成静态文件,会在当前目录下生成一个新的叫做public的文件夹
hexo s 启动本地web服务,用于博客的预览
hexo deploy (hexo d) 部署播客到远端

1
2
$ hexo new 'postName' --- 新建文章
$ hexo new page "pageName" --- 新建页面

常用简写

1
2
3
4
$ hexo n == hexo new
$ hexo g == hexo generate
$ hexo s == hexo server
$ hexo d == hexo deploy

目前安装所用的本地环境如下:(可以通过hexo -v查看)

Hexo 主题设置

安装主题

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

启用主题

修改Hexo目录下的_config.yml配置文件中的theme属性,将其设置为next

更新主题

1
2
3
4
$ cd themes/next
$ git pull
$ hexo g # 生成
$ hexo s # 启动本地web服务器

部署Hexo到Github Pages

使用hexo deploy部署

1
2
3
4
5
修改Hexo目录下的_config.yml配置文件
deploy:
type: git
repo: git@github.com:username/username.github.io.git
branch: master

需要提前安装一个扩展

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

然后在命令行中执行

1
$ hexo d

使用git命令行部署

1
2
$ cd hexo/blog
$ git clone https://github.com/username/username.github.io.git .deploy/username.github.io

将github上创建的博客克隆到本地,新建一个目录叫做.deploy用于存放克隆的代码

创建一个deploy脚本文件

1
2
3
4
5
6
$ hexo generate
$ cp -R public/ .deploy/username.github.io
$ cd .deploy/username.github.io
$ git add .
$ git commit -m “update”
$ git push origin master

Hexo 配置主题

主题配置在themes文件下_config.yml

参考链接

手把手教你使用Hexo + Github Pages搭建个人独立博客
我是如何利用Github Pages搭建起我的博客,细数一路的坑
hexo你的博客