Hexo搭建个人BLOG

Posted by Chen22 on 2016-11-06

Hexo介绍#

[使用 Hexo 为自己在 Github 上建一个静态 Blog 站点][1]
[1]: http://xiaolai.li/2016/06/22/makecs-build-a-blog-with-hexo-on-github/ “使用 Hexo 为自己在 Github 上建一个静态 Blog 站点”

[用 Hexo 搭建个人博客-01:6 步初体验][3]
[3]: http://www.jianshu.com/p/6bd12ab160fa “用 Hexo 搭建个人博客-01:6 步初体验”

本文介绍了Hexo搭建博客的主要步骤,以及迁移Hexo到新环境遇到的问题以及解决方案。

环境和工具准备#

工具准备#

  • git
  • npm
  • hexo

GIT#

GIT安装#

关于GIT的用法,可以参考《Pro Git》

1
git -v

NPM#

1
npm -v

安装#

REPO准备#

  • 准备一个REPO
    • 自己本来就有
    • REPO的申请方法可以参考

安装HEXO#

  • npm install hexo -g
  • npm install hexo-cli -g
    • 这一步出错,暂时不管

准备本地目录#

  • clone到本地,这部似乎是非必须的
  • Hexo初始化本地目录
1
2
3
4
hexo init yourname.github. c  youname.github.io
npm install hexo-deployer-git --save
hexo generate
hexo server
  • 在地址栏里输入: localhost:4000

  • 发布到github上

    • 编辑_config.yml:
1
2
3
deploy
type: git
repo: https://github.com/yourname/yourname.github.io.git

配置#

标签页#

在终端窗口下,定位到 Hexo 站点目录下。使用 hexo new page 新建一个页面,命名为 tags :

1
2
$ cd your-hexo-site
$ hexo new page tags

分类页#

在终端窗口下,定位到 Hexo 站点目录下。使用 hexo new page 新建一个页面,命名为 categories :

1
2
$ cd your-hexo-site
$ hexo new page categories


hexo迁移#

最近需要在另一台电脑部署hexo,将hexo的代码直接copy过去,遇到一些奇怪的问题。

问题一:#

在hexo的目录里面执行hexo clean,提示:

1
ERROR Plugin load failed: hexo-renderer-sass

采用很多方法,重装saas,安装也显示成功,最后还是不行。考虑到自己换了一个系统,可能hexo目录下面的node-moduels下面的库和npm版本并不兼容。采用PabloEzequiel commented on 3 Jan 2017的方法,删除node-module,重新安装依赖包

1
2
rm -rf node_module 
npm install

果然,成功了。

问题二:#

hexo g成功,但hexo s(server)时候,报错

1
WARN No layout: index.html出现这个问题会删除index.html的内容

出现这个问题,我先删除public里面的index.html文件。同时,发现theme里面文件不对,于是更新theme,然后重新generate

问题三:#

tags和categoreis不生效,导致BLOG的分类和标签页没有正确显示。
具体做法:

1
> hexo new page "tags"

edit tags/index.md

1
2
3
# tags/index.md
type: "tags"
layout: "tags"

edit categoreis/index.md

1
2
type: "categories"
layout: "categories"

问题四:#

update at 2021.03.21

ERR_INVALID_ARG_TYPE-HELPPP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ sudo hexo deploy
Password:
INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
FATAL 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:1972:10)
at copyFile (/Users/chenjing/work/hexo/node_modules/graceful-fs/graceful-fs.js:181:12)
at tryCatcher (/Users/chenjing/work/hexo/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/chenjing/work/hexo/node_modules/hexo-deployer-git/node_modules/hexo-fs/lib/fs.js:181:12
at tryCatcher (/Users/chenjing/work/hexo/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/chenjing/work/hexo/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/chenjing/work/hexo/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/chenjing/work/hexo/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/chenjing/work/hexo/node_modules/bluebird/js/release/promise.js:729:18)
at Promise._fulfill (/Users/chenjing/work/hexo/node_modules/bluebird/js/release/promise.js:673:18)
at Promise._resolveCallback (/Users/chenjing/work/hexo/node_modules/bluebird/js/release/promise.js:466:57)
at Promise._settlePromiseFromHandler (/Users/chenjing/work/hexo/node_modules/bluebird/js/release/promise.js:559:17)

这个问题一般是node版本太高所致。我当时的node版本是v14.16.0

Downgrade node#

1
2
3
4
5
# install n
$ npm install -g n
$ n 12
$ node -v
v12.21.0

Clean & Deploy#

1
2
3
$ hexo clean
$ hexo generate
$ hexo deploy

That’s done