官方文档

先决条件

建议使用最新的 hexo 版本和 node 版本

  • 安装 git 和 node.js
  • 安装 hexo-cli
  • 新建一个专属 hexo 的博客文件夹
1
npm install -g hexo-cli

配置 Hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 可以是其他目录,这里是 macOS 的 Documents 目录下创建的 hexo 文件夹
cd ~/Document/hexo

hexo init
// 安装博客依赖
npm install
npm install hexo-deployer-git --save

vim _config.yaml
# modify the top _config.yaml
deploy:
type: git
repository: https://github.com/*/*.github.io.git
branch: master

配置 git 用户与密钥信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# for Windows
ssh-keygen -t rsa -C "邮箱地址"
ssh-agent -s
eval `ssh-agent -s`
ssh-add
<!-- clip < ~/.ssh/id_rsa.pub -->

# for macOS
ssh-keygen -t rsa -C "邮箱地址"
pbcopy < ~/.ssh/id_rsa.pub

# add to GitHub SSH Key
ssh -T git@github.com
git config --global user.name "用户名"
git config --global user.email "邮箱"

部署

1
2
3
hexo clean
hexo generate -> hexo g
hexo deploy -> hexo d

使用技巧

在文章中使用本地图片

👍非常实用,极力推荐

1
2
3
4
5
6
7
8
9
vim _config.yml
post_asset_folder: true
marked:
prependRoot: true
postAsset: true

# install dependency
# 可以按照 markdown 的语句引用图片✌️
npm i -s hexo-asset-link

新建博客文章

1
hexo new "paper name"

新建草稿

1
hexo new draft "paper name"

更改主题

🪧目前使用的是 butterfly 主题

  • 在 themes 文件夹下 clone 其他优秀的主题

使用 butterfly 主题

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

# 在 _config.yml 中修改主题名称
theme: butterfly

使用 hexo-theme-matery 主题

1
2
3
4
git clone https://github.com/blinkfox/hexo-theme-matery.git

# 在 _config.yml 中修改主题名称
theme: hexo-theme-matery

使用 yelee 主题

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

# 在 _config.yml 中修改主题名称
theme: yelee

加入 README.md

1
2
3
4
# _config.yml
skip_render:
- README.md
- CNAME

文章中添加音乐

1
2
3
4
# 网易云音乐外链
<center>
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src=""></iframe>
</center>

添加评论(目前已经不采用了)

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
# visit https://github.com/imsun/gitment to download css and js
# 1. copy files
cp meta/gitment.css /2017/01/26/hexo/theme/your_theme/source/css/gitment.css
cp meta/gitment.js /2017/01/26/hexo/theme/your_theme/source/js/js.css
cp meta/gitment.ejs /2017/01/26/hexo/theme/your_theme/layout/_partial/gitment.ejs

# 2. regist GitHub OAuth Application and modify file gitment.ejs
owner: '',
repo: '',
oauth: {
client_id: '',
client_secret: '',
},

# 3. add css and js to head.ejs
vim /2017/01/26/hexo/theme/your_theme/layout/_partial/head.ejs
<link rel="stylesheet" href="/css/gitment.css">
<script src="/js/gitment.js"></script>

# 4. add ejs to article.ejs
vim /2017/01/26/hexo/theme/your_theme/layout/_partial/head.ejs

# add in the last line
<%- partial('gitment') %>

# 5. login in the GitHub page and initialize comment

# 限制
1. 域名加上 markdown 的文件名的字符串长度不能大于等于 50,
这是由于 GitHub Issue 的 label 限制