一、准备环境

  • node.js
  • npm

我的环境为MacOS环境。

二、安装hexo框架

  1. 切换到root用户

    1
    sudo su
  2. 安装npm淘宝源cnpm

    1
    npm install -g cnpm --registry=https://registry.npm.taobao.org
  3. 安装hexo

    1
    cnpm install -g hexo-cli

三、搭建博客

  1. 新建博客文件夹在~路径下

    1
    mkdir <文件夹命名>
  2. 初始化

    1
    sudo hexo init

四、启动博客

  • 用于在本地测试
    1
    hexo s

五、在github上新建开放仓库

  • 新建github.io仓库,必须以自己的用户名命名,如:
    1
    <GitHub的用户名>.github.io

六、安装git插件

  • 在博客文件夹目录下
    1
    cnpm install --save hexo-deployer-git

七、配置

配置推送的GitHub仓库
  • 编辑_config.yml文件,在最底部,配置:
    1
    2
    3
    4
    deploy:
    type: git
    repo: 仓库地址
    branch: master
更改主题
  1. <博客根目录>目录下,克隆主题,这里以yilia主题举例:

    1
    git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
  2. 配置_config.yml文件

  • 配置主题为yilia
    1
    theme: yilia

八、一些操作

  • 清除缓存

    1
    hexo clean
  • 在本地开启服务

    1
    hexo s
  • 推送到仓库

    1
    hexo d