Hexo 博客搭建与美化导航

特别说明
欢迎来到我的网站,此博客由【Hexo + Butterfly】来进行搭建。
本站所有内容仅供学习交流使用,不构成任何商业用途。内容因版本差异导致的问题,博主将尽力修正但不承担法律责任。
Hexo 博客版本:7.3.0
Butterfly 主题版本:5.3.5

🍅Hexo博客(五) 迁移操作 ⇦ 当前位置🍁

新电脑必要安装:

1 、 安装NodejsGit,方便后续编辑可再安装个Visual Studio Code

安装过程中重点记住两个点,一个是要添加 Git Bash Here 到右键菜单,一个是要把 Git 添加到全局变量。

安装 Git:【Git下载地址
安装 Node.js:【Node.js下载地址

2 、 全局‮换切‬淘宝镜像命令:

1
npm config set registry http://registry.npm.taobao.org/

3 、 全局安装 Hexo

1
npm install -g hexo-cli

迁移Hexo本地数据:

1 、拷贝原电脑项目文件中的到新电脑新建的文件夹中

1
2
3
4
5
6
7
_config.yml
_config.butterfly.yml
themes
source
scaffolds
package.json
.gitignore

2 、执行如下命令

使用 git bash 进入此新建文件夹

为新电脑全局安装hexo,安装Hexo项目依赖,以及安装hexo插件hexo-depolyer-git

1
2
3
4
npm install hexo-cli -g 
npm install
npm install hexo-deployer-git --save
hexo g; hexo s

生成新的连接秘钥:

  • 重新使用Git生成新的 ssh key,重新添加至你的Github,使当前电脑的Git与你的Github相连
1
2
3
git config --global user.name "Github名字"
git config --global user.email "********@qq.com"
ssh-keygen -t rsa -C "********@qq.com"

img

本地测试:

1 、 Git bash进行测试

1
hexo cl; hexo g; hexo s

2 、若本地成功部署,使用如下命令,部署至云端:

1
hexo cl; hexo g; hexo d

可能会遇到的问题:

在重新执行hexo部署命令时发生以下错误:

1
2
3
4
5
$ npm install hexo-cli -g
npm error code CERT_HAS_EXPIRED
npm error errno CERT_HAS_EXPIRED
npm error request to https://registry.npm.taobao.org/hexo-cli failed, reason: certificate has expired
npm error A complete log of this run can be found in: C:\Users\JiuGe\AppData\Local\npm-cache\_logs\2024-08-28T11_02_08_553Z-debug-0.log

这是因为证书原因,最直接的解决办法:关闭 npm ssl 严格证书检查

1
npm set strict-ssl false

执行完这条命令后再重新部署hexo,神奇功效。

部署至云端时若出现以下错误:

1
2
3
4
5
6
7
bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'https://github.com': No error
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'https://github.com': No error

解决方法:

  • _config.yml中,原来加过的github源地址,改为下面形式(可能是更换新电脑,项目未克隆到本地,而出现的 github 项目验证的问题)
1
2
3
4
5
deploy:
type: git
repository: ssh://git@github.com/你的Github名字/你的Github名字.github.io
# (注意username有大写换为小写,这样才能识别)
branch: master

总结

  • 要习惯性备份原电脑里的Hexo文件
  • 网上还是有很多自动备份的方法,可以再深入研究一下
  • 概括:新电脑重新安装好必要的NodejsGit,使用Git重新生成shh key,并配置到自己的Github,然后重新安装Hexo及相关依赖还有插件