hexo博客站点搭建及问题

搭建及部署

1. 安装运行环境

Node.js
git
安装最新版本即可,方法自行解决。

2. hexo 下载和安装
  1. 下载安装

    1
    $ npm install -g hexo-cli
  2. 设置环境变量(略)

  3. 去自定文件夹下进行初始化

    1
    2
    $ hexo init <folder>  ## folder 为自定义的文件夹名,比如我的是hexo-brave
    $ cd <folder>

    图片1

  4. 安装主题
    安装next主题(本站主题)为例

    1
    2
    $ cd hexo-brave
    $ git clone https://github.com/iissnan/hexo-theme-next themes/next

    主题文件安装到themes目录下面,如下图
    图片1
    然后参考Next模板使用文档 进行主题配置即可。

  5. 运行命令

1
$ hexo s --debug
  1. 生产静态文件

    1
    $ hexo g
  2. 发布

    1
    $ hexo d
  3. 部署到github

安装hexo-deployer-git程序

1
$ npm install hexo-deployer-git --save

配置_config.yml文件

1
2
3
4
deploy:
type: 'git'
repo: https://github.com/BraveChi/bravechi.github.io
branch: gh-pages

运行发布命令

1
$ hexo clean && hexo deploy

常用git命令

1
2
3
4
5
6
7
8
# 拉取代码
git pull origin main
# 提交代码
git status
git add .
git commit -m "******"
# 推送代码
git push -u origin main

问题及解决

  1. 提交失败的错误:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    fatal: unable to access 'https://github.com/BraveChi/bravechi.github.io/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
    FATAL {
    err: Error: Spawn failed
    at ChildProcess.<anonymous> (/Users/warrior/网站/github/hexo-brave/node_modules/hexo-util/lib/spawn.js:51:21)
    at ChildProcess.emit (node:events:513:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12) {
    code: 128
    }
    } Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

    解决方法:
    1
    2
    3
    rm -rf .deploy_git 
    git config --global core.autocrlf false
    hexo clean && hexo g && hexo d

参考 文档

  1. hexo官方文档
  2. hexo-deployer-git