Hexo搭建个人博客

前提准备

安装node.js

进入Node官网,安装node.js,打开cmd输入以下命令行:

1
2
3
4
5
6
# 验证版本信息
node -v
npm -v

# 该命令完成hexo的安装
npm install -g hexo-cli

配置hexo

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

1
2
3
hexo init    # 该命令完成hexo在本地博客目录的初始化
hexo g # 生成静态文件
hexo s # 开启本地预览

配置GitHub

配置站点配置文件

hexo 有2种 _config.yml文件,一个是根目录下的全局的 _config.yml,一个是各个主题 theme 下的 _config.yml。将前者称为站点配置文件, 后者称为主题配置文件

打开根目录下站点配置文件 _config.yml,配置有关 deploy 的部分:

部署到Github

1
2
3
npm install hexo-deployer-git --save   # 安装部署插件

hexo d # 该命令行必须使用git bash

网址: https://azreallem.github.io/ 能够正常访问即部署成功。

Hexo博客基本配置

更改主题

https://github.com/theme-next/hexo-theme-next

1
2
3
4
5
git clone https://github.com/theme-next/hexo-theme-next themes/next

# update
cd themes/next
git pull

启用主题,打开站点配置文件 _config.yml, 找到 theme 字段,并更改为 next,如下:

打开主题配置文件:themes\next_config.yml,找到 scheme 字段,并更改为 Gemini,如下:

上传到github

1
2
3
4
hexo clean # 清除缓存
hexo g # 生成
hexo s # server
hexo d # 部署

其他主题

https://github.com/Candinya/Kratos-Rebirth/

1
git clone [https://github.com/Candinya/Kratos-Rebirth/](https://github.com/Candinya/Kratos-Rebirth/) themes/kratos-rebirth

hexo常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
hexo new “postName” # 新建文章
hexo clean # 清除缓存
hexo generate # 生成静态页面至 public 目录
hexo server # 开启预览访问端口(默认端口 4000,’ctrl + c’关闭 server)
hexo deploy # 部署到 GitHub
hexo help # 查看帮助
hexo version # 查看 Hexo 的版本

# hexo常用命令
## 常见命令
1. hexo new “postName” # 新建文章
2. hexo clean # 清除缓存
3. hexo generate # 生成静态页面至 public 目录
4. hexo server # 开启预览访问端口(默认端口 4000,’ctrl + c’关闭 server)
5. hexo deploy # 部署到 GitHub
6. hexo help # 查看帮助
7. hexo version # 查看 Hexo 的版本
# 缩写
1. hexo n == hexo new
2. hexo g == hexo generate
3. hexo s == hexo server
4. hexo d == hexo deploy
# 组合命令
1. hexo s -g # 生成并本地预览
2. hexo d -g # 生成并上传
# 文章保存为草稿
1. 建立文章草稿
hexo new draft <title>
2. 本机预览草稿
hexo s --draft
3. 将草稿发布为正式文章
hexo p <filename>

参考教程

https://mumaxu.github.io/2018/12/09/GitHub-Hexo-从零开始搭建个人博客/

https://candinya.com/posts/Kratos-Rebirth-Manual/#Top-Menu-顶部导航栏相关