新电脑必要安装:

  1. 安装NodejsGit,方便后续编辑可再安装个Visual Studio Code
    安装过程中重点记住两个点,一个是要添加 Git Bash Here 到右键菜单,一个是要把 Git 添加到全局变量。

迁移Hexo本地数据:

  1. 拷贝原电脑项目文件中的_config.ymlthemessourcescaffoldspackage.json.gitignore到新电脑新建的文件夹中
  2. 使用git bash进入此新建文件夹:
  3. 执行如下命令(为新电脑全局安装hexo,安装Hexo项目依赖,以及安装hexo插件hexo-depolyer-git)以此一条条执行:
    1
    2
    3
    npm install hexo-cli -g 
    npm install
    npm install hexo-deployer-git --save

生成新的连接秘钥:

  1. 重新使用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"

本地测试:

  1. Git bash新建一个文章进行测试
1
2
3
hexo new "myNewTestBlog"
hexo g
hexo s
  1. 若本地成功部署,使用如下命令,部署至云端:
1
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

解决方法:

  1. _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及相关依赖还有插件