hexo结合github制作个人网页过程中error记录与解决

原本是打算写整个流程的,但是网上制作流程很详细的,所以我就不多此一举了,直接列出过程中遇到的error与解决方法供后来者参考。

1. hexo deployer(简化hexo d)出错Error:Spawn failed

Spawn failed 是一个综合性问题,很多情况都会触发,以下列出我所遇到的两种情况以及解决方法

1.1 科学上网导致ssh连接不到库
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FATAL Something’s wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: Spawn failed
at ChildProcess. (D:\Myblog\myblog\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (events.js:314:20)
at ChildProcess.cp.emit (D:\Myblog\myblog\node_modules\cross-spawn\lib\enoent.js:34:29)
at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)

因为国内众所周知的情况,大家要访问github肯定要科学上网,如果在hexo init的时候没有科学上网或者使用加速器,但是为了看hexo是否上传成功肯定又要科学上网或使用加速器。这IP变换的过程就会导致hexo d的时候ssh连接不到

这种情况就很好解决了,保持hexo init和hexo d的时候IP地址一致就好了。

1.2 git进行push或者hexo d的时候改变了一些.deploy_git文件下的内容。
INFO  Validating config
INFO  Start processing
INFO  Files loaded in 145 ms
INFO  Generated: archives/index.html
INFO  Generated: index.html
INFO  Generated: css/style.css
INFO  Generated: fancybox/jquery.fancybox.min.css
INFO  Generated: js/script.js
INFO  Generated: archives/2024/12/index.html
INFO  Generated: fancybox/jquery.fancybox.min.js
INFO  Generated: js/jquery-3.6.4.min.js
INFO  Generated: archives/2024/index.html
INFO  Generated: css/images/banner.jpg
INFO  Generated: 2024/12/24/Christmas-Eve/index.html
INFO  Generated: 2024/12/23/hello-world/index.html
INFO  Generated: 2024/12/23/12-23-record/index.html
INFO  13 files generated in 366 ms
INFO  Deploying: git
INFO  Setting up Git deployment...
Initialized empty Git repository in D:/myblog/.deploy_git/.git/
[master (root-commit) b991765] First commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 placeholder
INFO  Clearing .deploy_git folder...
INFO  Copying files from public folder...
INFO  Copying files from extend dirs...
warning: in the working copy of '2024/12/23/12-23-record/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of '2024/12/23/hello-world/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of '2024/12/24/Christmas-Eve/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'archives/2024/12/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'archives/2024/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'archives/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'css/style.css', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'fancybox/jquery.fancybox.min.js', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'js/jquery-3.6.4.min.js', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'js/script.js', LF will be replaced by CRLF the next time Git touches it
[master 68ed85f] Site updated: 2024-12-27 18:39:16
 14 files changed, 3192 insertions(+)
 create mode 100644 2024/12/23/12-23-record/index.html
 create mode 100644 2024/12/23/hello-world/index.html
 create mode 100644 2024/12/24/Christmas-Eve/index.html
 create mode 100644 archives/2024/12/index.html
 create mode 100644 archives/2024/index.html
 create mode 100644 archives/index.html
 create mode 100644 css/images/banner.jpg
 create mode 100644 css/style.css
 create mode 100644 fancybox/jquery.fancybox.min.css
 create mode 100644 fancybox/jquery.fancybox.min.js
 create mode 100644 index.html
 create mode 100644 js/jquery-3.6.4.min.js
 create mode 100644 js/script.js
 delete mode 100644 placeholder
fatal: unable to access 'https://github.com/ikekyrie/ikekyle.github.io.git/': Failed to connect to github.com port 443 after 21062 ms: Couldn't connect to server
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 (node:events:519:28)
    at cp.emit (D:\myblog\node_modules\cross-spawn\lib\enoent.js:34:29)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)

排除了ssh连接失败这种情况,大概率是因为这个例子里的原因。这种情况直接把hexo init创建的那个文件夹里.deploy_git和public的文件夹删掉暴力解决就好了,这两个文件夹会在hexo d的时候自动创建,所以不用担心会有什么影响。

1.3 http协议连接到github响应时间长导致spawn failed
warning: in the working copy of '2024/12/23/12-23-record/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of '2024/12/23/hello-world/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of '2024/12/24/Christmas-Eve/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of '2024/12/27/12-27-record/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of '2025/01/07/1-7-record/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'archives/2024/12/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'archives/2024/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'archives/2025/01/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'archives/2025/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'archives/index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'css/style.css', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'fancybox/jquery.fancybox.min.js', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'index.html', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'js/jquery-3.6.4.min.js', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'js/script.js', LF will be replaced by CRLF the next time Git touches it
[master 3fd5069] Site updated: 2025-01-07 16:45:03
 6 files changed, 10 insertions(+), 10 deletions(-)
fatal: unable to access 'https://github.com/ikekyrie/ikekyrie.github.io.git/': Failed to connect to github.com port 443 after 21044 ms: Couldn't connect to server
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 (node:events:519:28)
    at cp.emit (D:\myblog\node_modules\cross-spawn\lib\enoent.js:34:29)
    at ChildProcess._handle.onexit (node:internal/child_process:294:12)

解决过程:

1)先通过ping确认链接github没问题

Pinging github.com [20.205.243.166] with 32 bytes of data:
Reply from 20.205.243.166: bytes=32 time=216ms TTL=101
Reply from 20.205.243.166: bytes=32 time=217ms TTL=101
Reply from 20.205.243.166: bytes=32 time=216ms TTL=101
Reply from 20.205.243.166: bytes=32 time=216ms TTL=101

Ping statistics for 20.205.243.166:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 216ms, Maximum = 217ms, Average = 216ms

2)增加git超时时间

git config --global http.postBuffer 524288000
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 99999

然后hexo clean;hexo generate; hexo d就正常了。

以上两个情况解决后我就顺利hexo d到github的个人网页库了。之后就遇到了网页404的情况,以下解决hexo d没问题,但是网页还是没有内容的问题。

2 网页404
2.1 github设置的网页的那个库Setting没有修改。

要想网页搭建成功,github网页库里Setting中Pages设置必须和图里一样,尤其注意Branch必须设置main(这里和.config的deploy中一样)否则会出错。

deploy:
  type: git
  repo: https://github.com/ikekyrie/ikekyrie.github.io.git
  branch: main
2.2 网页地址和设置的不一样,https://username.github.io后还有一长串。

这是因为库的username和GitHub用户名不一样

我原本用户名为ikekyrie,但是库打算设置成ikekyle.github.io结果就是网页域名变成https://ikekyrie.github.io/ikekyle.github.io。

虽然打开还是能打开,内容也在,但是hexo的网页UI模板不会反应在网页上,很丑,所以建议还是得将username和用户名改一致,这样不用重新hexo d就直接解决了(记得改.config的deploy的信息)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值