准备工作

  1. 安装Node.js

安装Hexo

  1. 下载Hexo
    1
    npm install -g hexo-cli
  2. 创建并打开文件夹
    1
    2
    mkdir your_folder
    cd your_folder
  3. 初始化Hexo
    1
    hexo init

主题及插件

安装主题

可以去Hexo官方主题库选择喜欢的主题,命令如下

1
2
# xxx为主题的git仓地址
git clone -b master xxx themes/xxx

我用的是butterfly主题

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

安装插件

可以去Hexo官方插件库按需安装插件,命令如下

1
2
# xxx为插件名称
npm install xxx --save

下面是我常用的一些

  1. 渲染Pug(原Jade)文件,可以将Pug文件转换为HTML
    1
    npm install hexo-renderer-pug --save
  2. 渲染Stylus文件,可以将Stylus转换为CSS
    1
    npm install hexo-renderer-stylus --save

配置主题

  1. 打开_config.yml文件
  2. 找到theme配置
  3. 配置主题
    1
    theme: butterfly

PS:关于主题具体的配置参数及相关设置,请前往对应主题的官网进行查看,此处不做详细介绍。

首次部署

  1. 安装依赖npm,防止启动报错
    1
    npm install
  2. 清理缓存
    1
    hexo clean
  3. 生成静态文件
    1
    hexo g
  4. 启动服务
    1
    hexo s
  5. 打开本地地址

第一篇博客文章

分类

  1. 创建分类指标
    1
    hexo new page categories
  2. 在本地source/目录下会出现categories目录
  3. 打开source/categories/index.html文件,默认为
    1
    2
    3
    4
    ---
    title: categories
    date: xxx
    ---
  4. 添加type: categories到文件中
    1
    2
    3
    4
    5
    ---
    title: 分类
    date: xxx
    type: categories
    ---

写作

  1. 创建新文章或页面
    1
    2
    # xxx为文章标题
    hexo new xxx
  2. 由于文章默认会添加到source/_psot/目录下,可以根据自己需求手动调整文章目录。只需要保证在_post目录下即可,多少二级目录都无所谓,在静态编译后都会放到指定位置中去。