Hexo博客搭建

一、前期准备

  • GitHub账户
  • Node.js
  • Git
  • Hexo安装

检验是否安装成功

1
2
3
git --version
node -v
npm -v

Hexo安装

  • 新建一个文件夹,自己重命名文件夹(如:E\Blog),博客相关文件将储存在此文件夹下

  • 在该文件夹下右键鼠标,点击 Git Bash Here,输入以下 npm 命令即可安装

    • 1
      npm install hexo-cli -g
  • Hexo 初始化配置

    • 1
      2
      3
      npx hexo init blog
      cd blog
      npm install hexo-deployer-git --save
    • source 文件夹:源码,未被Hexo渲染的md文件,写的文章就在这里面
    • themes 文件夹:主题,安装的主题都在这
    • _config.yml:Hexo配置文件

本地查看效果

执行完以下命令即可登录 http://localhost:4000/ 查看效果

(尝试在命令的前面加上npx

1
2
hexo generate
hexo server

二、为博客更换自己喜欢的主题

  • butterfly 主题官网: https://butterfly.js.org/

  • 1
    git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
  • 修改 Hexo 根目录下的 _config.yml,把主题改为 butterfly
  • 1
    theme: butterfly
  • 安裝pug 以及 stylus 的渲染器

  • 1
    npm install hexo-renderer-pug hexo-renderer-stylus --save
  • 在 hexo 的根目录创建一個文件 _config.butterfly.yml,并把主題目录的 _config.yml 內容复制到 _config.butterfly.yml 去。

  • 注意:

    複製的是主題的 _config.yml ,而不是 hexo 的 _config.yml

    不要把主題目錄的 _config.yml 刪掉

    以後只需要在 _config.butterfly.yml 進行配置就行。如果使用了 _config.butterfly.yml, 配置主題的 _config.yml 將不會有效果。

    作者: Jerry
    連結: https://butterfly.js.org/posts/21cfbf15/
    來源: Butterfly
    版權屬於作者所有。商業用途請聯絡作者獲得授權,非商業用途請註明出處。