环境准备

  • Windows 10
  • Git
  • NodeJs
  • Gitee 账号
  • Github 账号
  • 域名一个(可选)

本地搭建

在新建的hexo 目录下执行

  1. cnpm 安装Hexo

    cnpm install -g hexo-cli
    cnpm install hexo –save

  2. 检查Hexo是否安装成功

    hexo -v

  3. 在hexo目录下新建目录hexo-blog,并执行命令

    hexo init

    node_modules: 依赖包
    public:存放生成的页面
    scaffolds:生成文章的一些模板
    source:用来存放你的文章
    themes:放下下载的主题
    _config.yml: 博客的核心配置文件(设置主体、标题等属性)

  4. 执行下面命令

    cnpm install

  5. 启动安装好的hexo

    hexo s -g

  6. 访问:http://localhost:4000

安装主题

  1. 挑选主题

    https://hexo.io/themes/

  2. 已A-Ayer主题为例,在hexo/hexo-blog目录下执行命令:

    git clone https://github.com/Siricee/hexo-theme-Chic.git themes/Chic

    注意:如果很慢的话可在末尾添加 –depth=1

    depth用于指定克隆深度,为1即表示只克隆最近一次commit.

  3. 修改配置文件_config.xml配置

    theme: Chic

  4. 启动hexo即可

    hexo s -g

托管Gitee

  1. 新建仓库hexo-blog

  2. 修改_config.yml文件,添加你创建的itee仓库地址

    1
    2
    3
    4
    deploy:
    type: git
    repo: <https://gitee.com/isspark/hexo-blog.git>
    branch: master
  3. 发布

  4. 安装自动部署发布工具:cnpm install hexo-deployer-git –save

  5. 发布:hexo clean && hexo g && hexo d

  6. 进入Gitee在仓库,服务->Gitee Pages,采用默认配置,点击更新即可

如有样式问题,修改_config.yml中配置

托管Github

  1. 创建GitHub仓库,并命名xxxx.github.io,建议xxxx替换为你Github的账号名

  2. 配置_config.yml

    1
    2
    3
    4
    deploy:
    type: git
    repo: <git@github.com>\:isspark/isspark.github.io.git
    branch: master
  3. 发布

    1
    2
    3
    4
    # 安装自动部署发布工具
    > cnpm install hexo-deployer-git --save
    # 发布:执行下面命令后,进入Gitee在仓库,服务->Gitee Pages,采用默认配置,点击更新即可
    > hexo clean && hexo g && hexo d
  4. 自定义域名

  • 将域名指向GitHub的服务器地址, 192.30.252.153 和 192.30.252.154
  • 进入存放博客的GitHub仓库,点击settings,设置Custom domain,输入www.crazyz.cn
  • 本地博客文件source中创建一个名为CNAME文件,不要后缀。写上内容你的域名
  • 发布:hexo clean && hexo g && hexo d

基本操作

生成标签和分类

1
2
3
4
5
6
7
8
9
10
## 生成标签
> hexo new page tags
INFO Created: ~/Documents/blog/source/tags/index.md
## 生成分类
> hexo new page categories
INFO Created: ~/Documents/blog/source/categories/index.md
## 生成文章
> hexo new post <文章名称>
## 发布
> hexo clean && hexo g && hexo d

对文章进行分类和添加标签

在文章文件头部添加下列:

---
categories: 
- Git
tags:
- Git
- 表格
- 表单验证
---

常见错误

设置了tag和category,但是没有显示出来

1.设置/tags/index.md 和 /categories/index.md如下:

1
2
3
4
5
6
7
8
9
10
11
12
---
title: tags
type: tags
layout: tag
---

---
title: categories
type: categories
layout: category
---

2.注意,在上文的layout值需要与主题文件夹下的/layout对应的tag和category 后缀ejs文件对应

_config.yml配置说明

https://hexo.io/zh-cn/docs/configuration.html