配置步骤
- 创建github pages
- 创建本地hexo环境
- 选择hexo主题
- 优化配置
创建github pages
登录github,创建一个新的repository,但仓库名的格式必须为:github账号名.github.io
创建hexo环境
$ hexo init <folder>
$ cd <folder>
$ npm install
更多配置信息,可以参考Hexo文档
选择Hexo主题
我使用的是Next,可以从github上下载https://github.com/iissnan/hexo-theme-next
需要注意的是,按照github上指令安装的版本是5.1.2版本,但如果想添加第三方Valine的评论功能,需要安装5.1.3以上的版本
Next具体细节可以参考Next文档
优化配置
- 配置git
因为要将最新的博客,上传到github上,需要输入以下指令
$ hexo clean
$ hexo g -d
而执行hexo g -d 需要用户输入其相应的github账号名和密码,为了避免每次提交,都输入账号和密码,需要设置SSH keys,具体可以参考廖雪峰git教程
2. 添加评论
这里用到了next中集成的第三方服务
Hexo的评论系统有很多,常见的有
- 多说
- 网易云跟帖
- 畅言
- 来必力(LiveRe)
- Disqus
- Hypercomments
- valine
其中多说和网易云已经失效,而来必力用的是国外服务器,每次加载都很慢,所以建议使用valine
具体可以参考
https://www.bluelzy.com/articles/use_valine_for_your_blog.html
3. 添加动态效果
看到别人使用hexo搭建的博客有酷炫的动态效果,上网搜了一下后发现,其实实现起来很方便
前端效果
https://segmentfault.com/a/1190000009544924
4. 代码高亮
在站点的_config.yml中如下配置
highlight:
enable: true
line_number: true
auto_detect: true
tab_replace: false
其中tab_replace需要设置成false,tap会全被true替代
5. 代码段折叠
写LeetCode题解时,发现代码太长了,影响阅读,所以想实现一下代码段的折叠
具体参考
https://www.cnblogs.com/woshimrf/p/hexo-fold-block.html