踩坑hexo

hexo个人踩坑

关于建站什么的就不说了,网上已经有很多链接,这里仅记录自己遇到的问题。

hexo d不成功

报错

1
Error: Spawn failed

原因:网络问题或者github被墙

我在学校用联通的Chinaunicom无法访问github

解决:换个网或者挂代理


图片上传问问题

hexo上传图片目前我知道有两种办法

第一种是利用图床,即第三方网站上传图片再用链接指向

  • 优点:不占git空间
  • 缺点:图片管理过于麻烦

第二种是用相对路径在本地插入

  1. 将_config.yml中的post_asset_folder改为true

  2. 在hexo目录下执行

    1
    npm install hero-asset-image --save
  3. 这是用hext new “”会在source下生成文章同名文件夹

  4. 将图片放入文件夹再用相对路径指向即可

    1
    ![](xxxx/example.jpg)

这种方式在用hexo g部署的时候在pulic/2019/0x/xx/index.html中的相关字段

html标签内的语句是img src = “2018/04/19/xxxx/图片名.jpg”而不是imgsrc=”xxxx.图片名.jpg”

⚠️注意:不能自己指定相对路径哟,typora生成的路径是不行滴

如果图片不显示

html也未修改,则采用以下办法

将博客根目录的packge.json中的”hero-asset-image”字段由”1.0.0”修改为”0.0.1”

1
"hexo-asset-image": "^0.0.1"

再在博客根目录执行

1
hexo install

更新之后即可

1
hexo clean && hexo g && hexo s

[感谢这位博主提供的方法][https://alreadyright.github.io/2019/06/16/aboutHexo/]

[参考了这位同学][https://blog.csdn.net/qq_40265501/article/details/80019774]

添加github和email后报错

Unhandled rejection Error: ENOENT: no such file or directory, open ‘/Users/felixxiong/FelixXiongHexoFolder*/themes/next/layout/_scripts/schemes/.swig

这是一个小问题,将链接前的socal取消注释即可。

升级node引发的问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
ATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError [ERR_INVALID_ARG_TYPE]: The "mode" argument must be integer. Received an instance of Object
at copyFile (fs.js:1895:10)
at tryCatcher (/Users/luodi/githubblog/node_modules/bluebird/js/release/util.js:16:23)
at ret (eval at makeNodePromisifiedEval (/usr/local/lib/node_modules/hexo-cli/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:13:39)
at /Users/luodi/githubblog/node_modules/hexo-fs/lib/fs.js:144:39
at tryCatcher (/Users/luodi/githubblog/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:729:18)
at Promise._fulfill (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:673:18)
at Promise._resolveCallback (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:466:57)
at Promise._settlePromiseFromHandler (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:559:17)
at Promise._settlePromise (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:729:18)
at Promise._fulfill (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:673:18)
at Promise._resolveCallback (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:466:57)
at Promise._settlePromiseFromHandler (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:559:17)
at Promise._settlePromise (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:729:18)
at Promise._fulfill (/Users/luodi/githubblog/node_modules/bluebird/js/release/promise.js:673:18)

解决办法:升级hexo或回退node

自己把md放到source下面

这样的问题在于没有tag和date,不会按照时间排序

修改文章名字问题

不能直接修改,建议删掉重new

next目录乱码问题

这个暂时还没解决,只好不用目录了。

添加背景图片

hexo\themes\next\source\images\ 的路径下存放图片

修改themes\next\source\css\ _custom\custom.styl文件,添加以下代码

1
2
3
4
5
6
7
body {
background:url(/images/图片.jpg);
background-repeat: no-repeat;
background-attachment:fixed;
background-position:50% 50%;
background-size:cover;
}

修改不透明度

1
2
3
.main-inner {
opacity: 0.85;
}

首页不能访问

出现乱码:

1
{% extends '_layout.swig' %} {% import '_macro/post.swig' as post_template %} {% import '_macro/sidebar.swig' as sidebar_template %} {% block title %}{{ config.title }}{% if theme.index_with_subtitle and config.subtitle %} - {{config.subtitle }}{% endif %}{% endblock %} {% block page_class %} {% if is_home() %}page-home{% endif -%} {% endblock %} {% block content %} {% for post in page.posts %} {{ post_template.render(post, true) }} {% endfor %} {% include '_partials/pagination.swig' %} {% endblock %} {% block sidebar %} {{ sidebar_template.render(false) }} {% endblock %}

运行

1
2
3
4
5
npm i hexo-renderer-swig

hexo c
hexo g
hexo s

常用命令

全局升级hexo-cli

1
npm i hexo-cli -g

升级hexo:修改 package.json 文件“dependencies”下对应的hexo版本号

1
npm update

更新hexo博客

1
2
hexo clean
hexo d -g

新建文章

1
hexo new "文章名"