hexo使用手册

前言

hexo_blog的是使用、备份并且在新Mac上还原。

安装环境

Node.js

安装Hexo

1
2
3
4
5
6
7
8
npm install hexo-cli -g
cd blog(我的项目路径)
hexo init
npm install
hexo generate
hexo server
此时可在 http://localhost:4000/ 查看
Ctrl+C停止

将本地文件部署到Github

1
2
3
4
打开 blog下_config.yml,修改deploy标签。
deploy type: github(或者git)
repository: git地址(如果Github开启两步验证:git@github.com:XXX/XXX.github.io.git)
branch: master

进入blog

1
2
3
4
5
6
7
8
9
10
11
hexo clean
hexo generate
hexo deploy
出现错误后修改_config.yml中type: git,然后执行

npm install hexo-deployer-git --save
然后继续

hexo clean
hexo generate
hexo deploy

写博文

1
hexo new "文章题目"

发表

1
2
3
4
5
6
7
8
9
hexo clean
hexo generate
(hexo server预览)
hexo deploy

hexo n == hexo new
hexo s == hexo server
hexo g == hexo generate
hexo d == hexo deploy

安装主题

以next为例

下载主题

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

打开blog下_config.yml,修改theme为next,然后三步曲

1
2
3
hexo clean
hexo g
hexo d

域名解析

可以在 dnspod 购买

source文件夹下创建CNAME,内容为购买过的域名

在域名管理中添加记录

备份Github

先删除theme的.git

1
find . -name ".git" | xargs rm -Rf

在blog下

1
2
3
git init
git add .
git status

此时如果有 modified: themes/next (modified content) ,使用 git diff themes/next 有类似如下信息

1
2
-Subproject commit XXXX
+Subproject commit XXXX-dirty

此时可使用

1
git status --ignore-submodules=dirty

然后 git status 正常
继续执行

1
2
3
git commit -m "first commit"
git add remote 新的repo
git push origin master

还原Github备份

1
2
3
4
5
6
7
git clone
cd blog
npm install hexo
npm install
npm install hexo-deployer-git
npm install hexo-cli -g
git clone https://github.com/iissnan/hexo-theme-next themes/next

直接替换其他地方备份的 next 文件夹

后记

本文方法备份Github的时候需要删除主题例如themes/next下的.git,clone blog完成的时候还需要再重新clone主题。如果有其它更简单的备份请留言交流