hexo使用

使用Hexo+Github部署
参考官方文档:https://hexo.io/docs/

安装

1
2
3
4
cnpm install -g hexo-cli  或者 cnpm install  hexo  安装Hexo
hexo init <foldername> 新建一个Hexo项目
cd foldername
cnpm install 安装依赖

写博客

1
2
hexo new [layout] <title> 新建一个帖子/页面/草稿   分别对应layout中post/page/draft  title是名字  对于草稿写完后还需要 hexo publish [layout] <title>
//创建post时可以根据scaffolds中的模板进行创建 命令为 hexo new <模板名字> <post名字> 例如scaffolds中有一个a.md 以它为模板的命令为 hexo new a “hi”

部署在github上

首先在github上创建huajiaohuixiang.github.io的Repo
然后在本地hexo下

1
2
3
4
5
6
git init
git branch -M main
git remote add origin https://github.com/huajiaohuixiang/huajiaohuixiang.github.io.git
git add .
git commit -m "first commit"
git push origin -u origin main 第一次需要-u origin commit

然后安装hexo-deployer

1
2
3
4
5
6
cnpm install hexo-deployer-git --save
修改 _config.yml 将deploy修改成下面(huajiaohuixiang应该改成你的repo名字)
deploy:
type: git
repo: https://github.com/huajiaohuixiang/huajiaohuixiang.github.io
branch: main

然后

1
2
hexo clean 
hexo deploy

打开https://huajioahuixiang.github.io即可
本人第一次hexo deploy的时候报错

1
2
3
4
5
6
7
FATAL {
err: Error: Spawn failed
at ChildProcess.<anonymous> (Y:\个人博客\hexo\node_modules\_hexo-util@2.4.0@hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (events.js:315:20)
at ChildProcess.cp.emit (Y:\个人博客\hexo\node_modules\_cross-spawn@7.0.3@cross-spawn\lib\enoent.js:34:29)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
}

在deploy一次就好了

可能有用的文章:
https://1187100546.github.io/2019/11/24/spawn-failed/
https://perry96.com/archives/882898e3.html 这个是回退本地git版本 回退了就好了,很奇怪