参考文献

hexo 官方文档

环境说明

  • node v12.13.1
  • mac

步骤说明

安装

全局安装

$ npm install -g hexo-cli

查看版本

$ hexo -v

$ hexo -v
hexo-cli: 4.2.0
os: Darwin 18.6.0 darwin x64
node: 12.13.1
v8: 7.7.299.13-node.16
uv: 1.33.1
zlib: 1.2.11
brotli: 1.0.7
ares: 1.15.0
modules: 72
nghttp2: 1.39.2
napi: 5
llhttp: 1.1.4
http_parser: 2.8.0
openssl: 1.1.1d
cldr: 35.1
icu: 64.2
tz: 2019c
unicode: 12.1

初始化项目

hexo init <folder>

hexo init "你的项目名称"
hexo init axin-theme

出现错误

fatal: unable to access 'https://github.com/hexojs/hexo-starter.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
WARN  git clone failed. Copying data instead
FATAL {
  err: [Error: ENOENT: no such file or directory, scandir '/usr/local/lib/node_modules/hexo-cli/assets'] {
    errno: -2,
    code: 'ENOENT',
    syscall: 'scandir',
    path: '/usr/local/lib/node_modules/hexo-cli/assets'
  }
} Something's wrong. Maybe you can find the solution here: %s http://hexo.io/docs/troubleshooting.html

解决办法:
sudo chown -R `whoami` /usr/local/lib/node_modules

# axin @ AxindeMacBook-Pro in ~/workspace/front [17:00:38]
$ hexo init axin-theme
INFO  Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
INFO  Install dependencies
warning hexo-renderer-stylus > stylus > css-parse > css > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning hexo-renderer-stylus > stylus > css-parse > css > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
warning hexo-renderer-stylus > stylus > css-parse > css > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
INFO  Start blogging with Hexo!

npm install

# axin @ AxindeMacBook-Pro in ~/workspace/front/axin-theme [17:13:19]
$ npm install

changed 1 package in 768ms

15 packages are looking for funding
  run `npm fund` for details

至此项目初始化完成

安装模板

hexo-theme-butterfly
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly

npm install hexo-renderer-pug hexo-renderer-stylus --save

静态网站生成

hexo generate

# axin @ AxindeMacBook-Pro in ~/workspace/php/axin-theme [17:34:19]
$ hexo generate
INFO  Validating config
INFO
  ===================================================================

      #####  #    # ##### ##### ###### #####  ###### #      #   #
      #    # #    #   #     #   #      #    # #      #       # #
      #####  #    #   #     #   #####  #    # #####  #        #
      #    # #    #   #     #   #      #####  #      #        #
      #    # #    #   #     #   #      #   #  #      #        #
      #####   ####    #     #   ###### #    # #      ######   #

                            3.7.1
  ===================================================================
INFO  Start processing
Deprecated as of 10.7.0. highlight(lang, code, ...args) has been deprecated.
Deprecated as of 10.7.0. Please use highlight(code, options) instead.
https://github.com/highlightjs/highlight.js/issues/2277
INFO  Files loaded in 2.13 s
INFO  Generated: archives/index.html
INFO  Generated: archives/2021/index.html
INFO  Generated: img/algolia.svg
INFO  Generated: img/favicon.png
INFO  Generated: index.html
INFO  Generated: archives/2021/04/index.html
INFO  Generated: img/404.jpg
INFO  Generated: css/var.css
INFO  Generated: js/utils.js
INFO  Generated: js/search/local-search.js
INFO  Generated: img/loading.gif
INFO  Generated: 2021/04/11/hello-world/index.html
INFO  Generated: img/friend_404.gif
INFO  Generated: js/tw_cn.js
INFO  Generated: js/main.js
INFO  Generated: js/search/algolia.js
INFO  Generated: css/index.css
INFO  17 files generated in 751 ms

预览

上传到自己的服务器目录下,配置好域名就表示你的Hexo站点搭建成功了