博客更新为Hexo
框架。
前言
记录一下博客的迁移。
这个博客最初是用Hexo
框架开发部署在Gitee
上的,后来一次偶然的机会知道了VitePress
,就想尝试一下,用了一段时间发现VitePress
体验不太好,比如博客的目录需要手动输入,博客不是按照更新顺序排列等。所以就决定把博客迁移回Hexo
框架。
Hexo 自动化部署到个人服务器上
保存源码到远程仓库
注意:这里保存的是源码,并不是博客的静态文件
- 在远程服务器上创建空仓库
git init --bare hexo.git # 创建空仓库 cd hexo.git git branch -m main # 重命名分支
- 在本地仓库中添加远程仓库并推送代码
git init --initial-branch=main # 初始化本地仓库
- 创建
.gitignore
文件,忽略本地仓库中不需要上传的文件。下面是.gitignore
文件内容:/public /node_modules /db.json
- 在本地仓库中添加文件并提交
git add. git commit -m "first commit" git remote add origin root@xxx/home/git/hexo.git # 添加远程仓库 git push -u origin main # 推送代码到远程仓库
部署 Hexo 到远程服务器
- 在远程服务器创建保存博客静态文件的裸仓库
git init --bare blog.git cd blog.git git branch -m main vim ./hooks/post-receive # 在hooks文件夹下创建post-receive文件 chmod 777 ./hooks/post-receive # 给文件添加执行权限
- 创建用于nginx的work-tree文件夹
mkdir /home/blog # 注意该文件需要有权限 chmod 777 /home/blog # 给文件添加执行权限
- 在
post-receive
文件中添加部署脚本git --work-tree=/home/blog --git-dir=/home/git/blog.git checkout -f
- 在本地Hexo文件中
_config.yml
文件中配置远程仓库地址deploy: type: git repo: root@xxx/home/git/blog.git branch: main
- 本地hexo文件安装依赖并部署博客
npm install hexo-deployer-git --save hexo clean hexo g hexo d
- 在远程服务器上配置nginx
在cd /usr/local/nginx/conf/ vim nginx.conf
server
块中添加如下内容:location /{ root /home/blog; index index.html index.htm; }