0%

hexo博客迁移-从一台PC到另一台PC

近段时间,因为在实验室里基本上都用实验室的PC,而不用笔记本。但如果想写笔记的话,需要用笔记本进行操作,并且来回相互很麻烦,于是就想把笔记本的hexo移动到实验室PC里,具体做法可以使用如下步骤:

1.按照环境搭建教程,把环境搭建起来(只安装好node.js,git,npm,cnpm,hexo以及使用命令hexo init即可),并下载依赖:

1
2
3
4
npm i hexo-server
npm install hexo-deployer-git --save
npm install hexo-generator-feed --save
npm install hexo-generator-sitemap --save

等hexo初始化成功后,将原电脑的以下文件全部拷贝过来:

1
2
3
4
5
_config.yml
package.json
scaffold/
source/
themes/

此时注意,现在可以用

1
2
3
hexo clean
hexo g
hexo s

等操作,但可能会报totalcount的错误,原因在于我使用了文章字数统计插件,需要另下载依赖:

1
npm install hexo-wordcount --save

由于配置已经全部拷贝过来了,所以只需要进行安装插件即可运行。

现在,可能会遇到这种错误:

1
2
3
4
5
6
7
fatal: unable to access 'https://github.com/MrSunCodes/MrSunCodes.github.io.git/': Failed to connect to github.com port 443: Timed out
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: Spawn failed
at ChildProcess.<anonymous> (D:\MyBlog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (events.js:375:28)
at ChildProcess.cp.emit (D:\MyBlog\node_modules\cross-spawn\lib\enoent.js:34:29)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)

我这边推荐使用ssh进行登录,具体做法是:
1.配置config文件,将仓库地址换为ssh:

1
2
3
4
deploy:
type: git
repo: git@github.com:your_github_user_name/your_github_user_name.github.io.git
branch: master

2.在命令行中输入以下代码进行生成ssh密钥:

1
ssh-keygen -t rsa -C somebody@qq.com(换成你的邮箱地址)

此时回车跳过所有选择即可。
3./c/Users/{你的用户名/.ssh/id_rsa.pub文件,将里面的ssh密钥复制出来,并在github里新建一个ssh
4.验证ssh key:

1
ssh -T git@github.com

如果出现下面语句,说明配置成功,可以正常进行hexo d进行上传博客了

1
Hi somebody! You've successfully authenticated, but GitHub does not provide shell access.

5.如果没有出现上面语句,而是出现connection reset,那么建议重新生成ssh,确保ssh有复制完全。