Hexo配置

安装hexo

1
$ npm install -g hexo-cli


安装完成后,使用hexo新建博客

1
2
3
hexo init myblog
cd myblog
npm install

目录如下

1
2
3
4
5
6
7
8
.
├── _config.yml
├── package.json
├── scaffolds
├── source
| ├── _drafts
| └── _posts
└── themes

使用pure主题,把pure从github克隆到themes目录中

1
git clone https://github.com/cofess/hexo-theme-pure.git themes/pure

然后修改_config.yml,把theme修改成pure

1
theme: pure

修改pure目录里的_config.yml,比如昵称等,然后启动hexo

1
2
hexo generate
hexo server

打开localhost:4000,结果如下:
avatar

安装图片插件

1
npm install hexo-asset-image --save

修改_config.yml配置文件post_asset_folder项为true。

1
post_asset_folder: true

运行hexo n “博客名”来生成md博客时,会在_post目录下看到一个与博客同名的文件夹。
把图片放到目录下,然后在文章中下面带码即可

1
![你想要输入的替代文字](xxxx/图片名.jpg)

自动部署到github

安装插件

1
npm install hexo-deployer-git --save

修改_config.yml

1
2
3
4
deploy:
type: git
repo: https://github.com/XinliNiu/XinliNiu.github.io.git
branch: master

密码不用输,需要之前git自己记住密码

另外,CNAME需要放到_posts目录里

1
blog.ifool.top

部署到github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
localhost:myblog niuxinli$ hexo deploy
INFO Deploying: git
INFO Clearing .deploy_git folder...
INFO Copying files from public folder...
INFO Copying files from extend dirs...
[master 965ce7f] Site updated: 2019-03-05 23:26:42
7 files changed, 721 insertions(+), 91 deletions(-)
create mode 100644 "2019/03/05/Hexo\351\205\215\347\275\256/hexo_hello_world.png"
create mode 100644 "2019/03/05/Hexo\351\205\215\347\275\256/index.html"
Counting objects: 17, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (17/17), 700.17 KiB | 0 bytes/s, done.
Total 17 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), completed with 4 local objects.
To https://github.com/XinliNiu/XinliNiu.github.io.git
b303736..965ce7f HEAD -> master
Branch master set up to track remote branch master from https://github.com/XinliNiu/XinliNiu.github.io.git.
INFO Deploy done: git

打开XinliNiu.github.io或者自定义到域名blog.ifool.top,就能看到主页了。
(未完待续)

评论

使用valine,注册https://leancloud.cn
参考
https://ioliu.cn/2017/add-valine-comments-to-your-blog/

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
# Comment
# Gitment
# Introduction: https://imsun.net/posts/gitment-introduction/
comment:
type: valine # 启用哪种评论系统
disqus: # enter disqus shortname here
youyan:
uid: 1783844 # enter youyan uid
livere:
uid: # enter youyan uid
gitment:
githubID:
repo:
ClientID:
ClientSecret:
lazy: false
gitalk: # gitalk. https://gitalk.github.io/
owner: #必须. GitHub repository 所有者,可以是个人或者组织。
admin: #必须. GitHub repository 的所有者和合作者 (对这个 repository 有写权限的用户)。
repo: #必须. GitHub repository.
ClientID: #必须. GitHub Application Client ID.
ClientSecret: #必须. GitHub Application Client Secret.
valine: #https://valine.js.org
appid: ggggggggggggggggggggggg # your leancloud application appid
appkey: ffffffffffffffffffffff # your leancloud application appkey
notify: false # mail notifier , https://github.com/xCss/Valine/wiki
verify: false # Verification code
placeholder: Just go go # comment box placeholder
avatar: mm # gravatar style
meta: nick,mail,link # custom comment header
pageSize: 10 # pagination size
visitor: true # Article reading statistic https://valine.js.org/visitor.html

wordcount

1
sudo npm install hexo-wordcount --save

修改主题里的_config.yml

1
2
3
4
5
# wordcount
postCount:
enable: true
wordcount: true # 文章字数统计
min2read: true # 阅读时长预计

这样就会在标题下显示文字个数和阅读时间。

1
Word Count: 502(words) Read Count: 2(minutes)

支持mathjax

参考下面的文章修改的,效果不错
https://blog.csdn.net/Aoman_Hao/article/details/81381507

在文章中启用mathjax

1
2
title: Hello World
mathjax: true

示例:

1
$$a^2 + b^2$$

生成的公式如下

导入github项目

复制theme/pure/_source/ 目录下repository文件夹到blog path/source/ 目录下
然后修改主题目录里的_config.yml

1
2
3
# Github
github:
username: *** # github username

引入豆瓣书单

复制theme/pure/_source/ 目录下books文件夹到blog path/source/ 目录下
修改主题里的_config.yml

1
2
3
4
5
# douban 豆瓣书单
douban:
user: *** # 豆瓣用户名
start: 0 # 从哪一条记录开始
count: 100 # 获取豆瓣书单数据条数

分享

修改主题里的_config.yml

1
2
3
4
5
6
# Share
# weibo,qq,qzone,wechat,tencent,douban,diandian,facebook,twitter,google,linkedin
share:
enable: true # 是否启用分享
sites: weibo,qq,wechat,facebook,twitter # PC端显示的分享图标
mobile_sites: weibo,qq,qzone # 移动端显示的分享图标

友情链接

复制theme/pure/_source/ 目录下links文件夹到blog path/source/ 目录下

在 hexo 目录下的 source 文件夹内创建一个名为 _data(禁止改名)的文件夹。
然后在文件内创建一个名为 links.yml 的文件,在其中添加相关数据即可。
单个友情链接的格式为:

1
2
3
4
牛哥的博客:
link: https://blog.51cto.com/nxlhero
avatar: https://s3.51cto.com/wyfs02/M01/10/99/wKioL1LODTCTUGHOAAAV14bOHIg296_middle.jpg
desc: "我的老博客,51cto推荐博客"

添加多个友情链接,我们只需要根据上面的格式重复填写即可。

about

把theme/pure/_source/里的about都复制到主目录的source里
about里的index.md可以自己定义。
index.md里写内容。在主题的_config.yml里写右边栏的东西

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
34
35
social:
links:
github: https://github.com/cofess
weibo: http://weibo.com/cofess
twitter: https://twitter.com/iwebued
# facebook: /
# dribbble: /
behance: https://www.behance.net/cofess
rss: atom.xml
link_tooltip: true # enable the social link tooltip, options: true, false
# My Skills
skills:
Java&JVM: ★★★★☆
C&C++: ★★★☆☆
Machine Learning: ★★☆☆☆
Security: ★★☆☆☆
Android: ★☆☆☆☆
Git: ★★★☆☆
# My Personal Links
links:
Github: https://github.com/XinliNiu
Blog: http://blog.ifool.top
# My Personal Labels
labels:
- 架构
- Java
- 云计算
- 机器学习
- 安全
# My Personal Works
works:
name:
link: http://www.example.com
date: 2016
# My Personal Projects

修改语言

在主目录下的_config.yml里修改language
en 英语
zh-Hans 大陆简体
zh-Hant-HK 港澳繁體
zh-Hant-TW 台灣正體

其它

把theme/pure/_source/里的categories、tags和about都复制到主目录的source里

替换掉打赏
进一步优化的可以参考
https://blog.cofess.com/2017/08/16/comon-plug-in-and-usage-of-hexo-blog.html