环境准备
- Windows 10
- Git
- NodeJs
- Gitee 账号
- Github 账号
- 域名一个(可选)
本地搭建
在新建的hexo 目录下执行
cnpm 安装Hexo
cnpm install -g hexo-cli
cnpm install hexo –save检查Hexo是否安装成功
hexo -v
在hexo目录下新建目录hexo-blog,并执行命令
hexo init
node_modules: 依赖包
public:存放生成的页面
scaffolds:生成文章的一些模板
source:用来存放你的文章
themes:放下下载的主题
_config.yml: 博客的核心配置文件(设置主体、标题等属性)执行下面命令
cnpm install
启动安装好的hexo
hexo s -g
安装主题
挑选主题
已A-Ayer主题为例,在hexo/hexo-blog目录下执行命令:
git clone https://github.com/Siricee/hexo-theme-Chic.git themes/Chic
注意:如果很慢的话可在末尾添加 –depth=1
depth用于指定克隆深度,为1即表示只克隆最近一次commit.
修改配置文件_config.xml配置
theme: Chic
启动hexo即可
hexo s -g
托管Gitee
新建仓库hexo-blog
修改_config.yml文件,添加你创建的itee仓库地址
1
2
3
4deploy:
type: git
repo: <https://gitee.com/isspark/hexo-blog.git>
branch: master发布
安装自动部署发布工具:cnpm install hexo-deployer-git –save
发布:hexo clean && hexo g && hexo d
进入Gitee在仓库,服务->Gitee Pages,采用默认配置,点击更新即可
如有样式问题,修改_config.yml中配置
托管Github
创建GitHub仓库,并命名xxxx.github.io,建议xxxx替换为你Github的账号名
配置_config.yml
1
2
3
4deploy:
type: git
repo: <git@github.com>\:isspark/isspark.github.io.git
branch: master发布
1
2
3
4安装自动部署发布工具
cnpm install hexo-deployer-git --save
发布:执行下面命令后,进入Gitee在仓库,服务->Gitee Pages,采用默认配置,点击更新即可
hexo clean && hexo g && hexo d自定义域名
- 将域名指向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 | ## 生成标签 |
对文章进行分类和添加标签
在文章文件头部添加下列:
---
categories:
- Git
tags:
- Git
- 表格
- 表单验证
---
常见错误
设置了tag和category,但是没有显示出来
1.设置/tags/index.md 和 /categories/index.md如下:
1 | --- |
2.注意,在上文的layout值需要与主题文件夹下的/layout对应的tag和category 后缀ejs文件对应