Hexo 搭建个人博客

此教程基本为当前blog的搭建过程,其中遇到的主要问题记录在下面,未来不定期更新。

1. 按照 Next 主题的步骤搭建

首先安装hexo官网教程安装hexo
https://hexo.io/docs/
然后将Next主题安装在theme文件夹内
https://github.com/iissnan/hexo-theme-next

2. 更换主题scheme,在theme/next/_config中更换scheme

1
2
3
4
5
# Schemes
#scheme: Muse
#scheme: Mist
#scheme: Pisces
scheme: Gemini

3. 新建文章

1
hexo new post "title"

4. 安装hexo-wordcount来显示每篇文章的字数,阅读时间等等

https://github.com/willin/hexo-wordcount

5. 更换markdown渲染工具,适配mathjax

1
2
npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save

6. 上传头像

将头像文件放置在/source/uploads/avatar.gif
在主题_config文件中找到avatar: 填上上述地址

7. 部署git

首先在github上建立一个repo,其名称为yourname.github.io,注意这里yourname需要跟你的github的用户名一致。然后在hexo的_config填写配置

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

然后用hexo生成静态网页,最后提交

1
2
3
hexo clean
hexo g
hexo d

8. 建立sitemap

安装sitemap生成工具

1
npm install hexo-generator-sitemap --save

然后在_config.yml中填写配置

1
2
3
# sitemap
sitemap:
path: sitemap.xml

最后用hexo生成,部署即可。

9. 增加文章分享功能

编辑主题配置文件,添加/修改字段jiathis,值为true

1
2
# JiaThis 分享服务
jiathis: true

10. 阅读次数统计( LeanCloud )

原文

  • LeanCloud 注册帐号
  • 创建应用,名称自拟
  • 创建Class,名称为Counter,选择无限制ACL权限
  • 设置-应用Key,复制App IDApp Key到主题配置文件
1
2
3
4
leancloud_visitors:
enable: true
app_id: 0CYW8yvHIgva4K5nBgVMLQaS-gzGzoHsz
app_key: hQM50ybVtNLAsEM3VPIHYSSk

11. 文章内anchor跳转

markdown语法中可以通过[link](#tile name)来跳转到特定的段落标题上,例如:

1
2
3
4
5
6
7
8
9
10
[link](#tile name)
点击上面的连接会跳转到下面的标题
1
2
3
4
5
6
### title name
跳转到上面的标题

但是在hexo中md转换为html后标题中的空格会转换为-因此上述连接需修改为[link](#tile-name)