搭建私人博客踩过的坑
最近闲来无事,和小伙伴研究研究搭建私人博客的问题本来,网上关于私人博客的教程有很多,于是照着一步一步下来,于是出事了…真的是“砰砰砰砰砰”,一步一雷,酸爽
事故大概是这样的:
cmd下hexo命令可以使用
Microsoft Windows [版本 10.0.17763.615]
(c) 2018 Microsoft Corporation。保留所有权利。
C:\Users\YBJB>hexo
Usage: hexo <command>
Commands:
help Get help on a command. init Create a new Hexo folder. version Display version information.
Global Options:
--config Specify config file instead of using _config.yml --cwd Specify the CWD --debug Display all verbose messages in the terminal --draft Display draft posts --safe Disable all plugins and scripts --silent Hide output on console
For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/
C:\Users\YBJB>
但是git Bash下却显示找不到
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ hexo
bash: hexo: command not found
我检查了一下node和npm都有,但是还是找不到hexo指令
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ node -v
v10.16.0
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ npm -v
6.9.0
探索
重装解决一切…然后又…
npm install XXX 没反应
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ npm install -g hexo-cli
[1]+ Stopped npm install -g hexo-cli
1 [sig] sh 22716! sigpacket::process: Suppressing signal 18 to win32 proce
ss (pid 396)
试过几次,每次都是没反应,不得不强退
于是猜测是不是网络原因
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ npm install -g hexo-cli --registry=https://registry.npm.taobao.org
C:\Users\YBJB\AppData\Roaming\npm\hexo -> C:\Users\YBJB\AppData\Roaming\npm\node
_modules\hexo-cli\bin\hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\hex
o-cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}
)
+ hexo-cli@2.0.0
added 187 packages from 433 contributors in 25.236s
这次带上了某宝的镜像,一开始还是没反应,但是最终在25s的时候完成,证明猜中了
装完之后,测试hexo
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ hexo
Usage: hexo <command>
Commands:
help Get help on a command. init Create a new Hexo folder. version
Display version information.
Global Options:
--config Specify config file instead of using _config.yml --cwd Specify
the CWD --debug Display all verbose messages in the terminal --draft Displ
ay draft posts --safe Disable all plugins and scripts --silent Hide output
on console
For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/
hexo init 报错
事情大概是这样的…
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ hexo init
FATAL D:\workspace\Blog not empty, please run `hexo init` on an empty folder and
then copy your files into it
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/do
cs/troubleshooting.html
Error: target not empty
at Context.initConsole (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-
cli\lib\console\init.js:23:27)
at Context.tryCatcher (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-c
li\node_modules\bluebird\js\release\util.js:16:23)
at Context.<anonymous> (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-
cli\node_modules\bluebird\js\release\method.js:15:34)
at Promise (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-cli\lib\cont
ext.js:39:9)
at Promise._execute (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-cli
\node_modules\bluebird\js\release\debuggability.js:313:9)
at Promise._resolveFromExecutor (C:\Users\YBJB\AppData\Roaming\npm\node_modu
les\hexo-cli\node_modules\bluebird\js\release\promise.js:488:18)
at new Promise (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-cli\node
_modules\bluebird\js\release\promise.js:79:10)
at Context.call (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-cli\lib
\context.js:35:10)
at findPkg.then.then.then (C:\Users\YBJB\AppData\Roaming\npm\node_modules\he
xo-cli\lib\hexo.js:67:17)
at tryCatcher (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-cli\node_
modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\YBJB\AppData\Roaming\npm\node
_modules\hexo-cli\node_modules\bluebird\js\release\promise.js:517:31)
at Promise._settlePromise (C:\Users\YBJB\AppData\Roaming\npm\node_modules\he
xo-cli\node_modules\bluebird\js\release\promise.js:574:18)
at Promise._settlePromise0 (C:\Users\YBJB\AppData\Roaming\npm\node_modules\h
exo-cli\node_modules\bluebird\js\release\promise.js:619:10)
at Promise._settlePromises (C:\Users\YBJB\AppData\Roaming\npm\node_modules\h
exo-cli\node_modules\bluebird\js\release\promise.js:699:18)
at Promise._fulfill (C:\Users\YBJB\AppData\Roaming\npm\node_modules\hexo-cli
\node_modules\bluebird\js\release\promise.js:643:18)
at Promise._resolveCallback (C:\Users\YBJB\AppData\Roaming\npm\node_modules\
hexo-cli\node_modules\bluebird\js\release\promise.js:437:57)
看完前两行就知道咋回事。。。原来是我手贱,在git Bash命令的时候顺手用了个git init 指令,结果导致Blog文件夹不为空,也就报了这个错,解决就是清空或者重建一个文件夹。
正确效果:
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/CBlog
$ hexo init
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
Cloning into 'D:\workspace\CBlog'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 81 (delta 0), reused 1 (delta 0), pack-reused 77
Unpacking objects: 100% (81/81), done.
Submodule 'themes/landscape'
(https://github.com/hexojs/hexo-theme-landscape.git) registered for path
'themes/landscape'
Cloning into 'D:/workspace/CBlog/themes/landscape'...
remote: Enumerating objects: 40, done.
remote: Counting objects: 100% (40/40), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 1018 (delta 16), reused 21 (delta 7), pack-reused 978
Receiving objects: 100% (1018/1018), 3.22 MiB | 54.00 KiB/s, done.
Resolving deltas: 100% (549/549), done.
Submodule path 'themes/landscape': checked out
'73a23c51f8487cfcd7c6deec96ccc7543960d350'
INFO Install dependencies
yarn install v1.17.3
info No lockfile found.
[1/4] Resolving packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
warning hexo > warehouse > cuid > core-js@1.2.7: core-js@<2.6.8 is no longer
maintained. Please, upgrade to core-js@3 or at least to actual version of
core-js@2.
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
[2/4] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info fsevents@1.2.9: The platform "win32" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check.
Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 301.13s.
INFO Start blogging with Hexo!
error set ting certificate verify locations:
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ git clone https://github.com/iissnan/hexo-theme-next themes/next
Cloning into 'themes/next'...
fatal: unable to access 'https://github.com/iissnan/hexo-theme-next/': error set
ting certificate verify locations:
CAfile: D:/IDEInstall/Git/usr/bin/curl-ca-bundle.crt
CApath: none
是的,在运行git clone 命令的时候证书位置有错了(我也不知道咋回事,以前是可以用的,大概是屋漏偏逢。。。哎),解决办法就是该对位置就好了
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ git config --system http.sslcainfo "D:\IDEInstall\Git\mingw64\ssl\certs\ca-bu
ndle.crt"
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/Blog (master)
$ git clone https://github.com/iissnan/hexo-theme-next themes/next
Cloning into 'themes/next'...
remote: Enumerating objects: 12037, done.
Receivingremote: Total 12037 (delta 0), reused 0 (delta 0), pack-reused 12037
Receiving objects: 100% (12037/12037), 13.05 MiB | 33.00 KiB/s, done.
Resolving deltas: 100% (6962/6962), done.
可以看到成功克隆下来了
fatal: The remote end hung up unexpectedly
今早继续搞结果又悲剧了,这个问题说它挂掉了。
为什么会挂掉,百度一波后,原因无非两点:墙、文件太大
- 方法一:修改提交缓存大小为500M,或者更大的数字
git config --global http.postBuffer 524288000
- 方法二:配置git的最低速度和最低速度时间:
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999 单位 秒
--global配置对当前用户生效,如果需要对所有用户生效,则用--system
- 方法三:换个更好的网络,比如把连的校园网(真的慢)断掉开热点之类的。
总结
想想都。。。。命途多舛,干啥啥出事也是可以的,单是搭框架就用了一个晚上(昨天弄到很晚,生物钟感觉快乱了)加早上一个小时,不过最终还是搭出来了欢迎来到我的博客,虽然这里还啥都没有,我曾经尝试过使用远程服务器当仓库(毕竟便宜),后来不知道啥原因,可能是仓库建的不对,本地git推不过去,有时间还得研究研究。
补充
Hexo博客出现“Cannot GET/xxx”错误
是的,装主题的时候又出毛病了,之前一直好的hexo g 命令竟然在public生成index.html 文件,于是查了一圈,各种方法都试过了,都没用比如:npm audit fix,再比如hexo c ,hexo g再来一遍,又或者npm ls --depth 0看看哪个插件没装之类,都试过了,没用。
一顿饭过后,越想越觉得是命令出问题了,配置是坑定没错的(在手贱运行 hexo c之前是好好的),就试着重装一遍npm install hexo-generator-index,由于万能的墙于是加了某宝镜像 npm install hexo-generator-index --registry=https://registry.npm.taobao.org,装完之后运行一遍hexo c和hexo g 成功。。。。
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/CBlog
$ npm install hexo-generator-index --registry=https://registry.npm.taobao.org
npm WARN rollback Rolling back node-pre-gyp@0.12.0 failed (this is probably harmless): EPERM: operation not permitted, lstat 'D:\workspace\CBlog\node_modules\fsevents\node_modules'
npm WARN rollback Rolling back readable-stream@2.3.6 failed (this is probably harmless): EPERM: operation not permitted, lstat 'D:\workspace\CBlog\node_modules\fsevents\node_modules'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ hexo-generator-index@0.2.1
added 1 package from 1 contributor, removed 1 package and audited 13847 packages in 7.778s
found 5 vulnerabilities (4 low, 1 critical)
run `npm audit fix` to fix them, or `npm audit` for details
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/CBlog
$ hexo clean
INFO Deleted database.
INFO Deleted public folder.
YBJB@LAPTOP-GC1JGK7U MINGW64 /d/workspace/CBlog
$ hexo g
INFO Start processing
INFO Files loaded in 5.42 s
INFO Generated: index.html
INFO Generated: archives/index.html
INFO Generated: tags/index.html
INFO Generated: categories/index.html
INFO Generated: link/index.html
INFO Generated: gallery/index.html
INFO Generated: img/comment_bg.png
INFO Generated: img/favicon.ico
INFO Generated: img/alipay.png
INFO Generated: archives/2019/index.html
INFO Generated: img/algolia.svg
INFO Generated: img/wechat.jpg
INFO Generated: img/cat.jpg
INFO Generated: archives/2019/08/index.html
INFO Generated: img/alipay.jpg
INFO Generated: img/friend_404.gif
INFO Generated: img/404.jpg
INFO Generated: css/var.css
INFO Generated: js/baidupush.js
INFO Generated: js/runtimeshow.js
INFO Generated: js/nightshift.js
INFO Generated: js/activate-power-mode.js
INFO Generated: js/utils.js
INFO Generated: css/index.css
INFO Generated: js/tw_cn.js
INFO Generated: js/main.js
INFO Generated: 2019/08/12/hello-world/index.html
INFO Generated: js/search/algolia.js
INFO Generated: js/search/local-search.js
INFO Generated: js/third-party/fireworks.js
INFO Generated: js/third-party/canvas-ribbon.js
INFO Generated: js/third-party/anime.min.js
INFO Generated: js/third-party/piao.js
INFO Generated: js/third-party/jquery.fancybox.min.js
INFO Generated: img/avatar.png
INFO Generated: js/third-party/jquery.min.js
INFO 36 files generated in 1.84 s