配置评论、搜索和代码

评论

gitment

  • gitment是挂在github的issue上,从github给的api上提交和拉取评论,然后界面(应该)是作者自己做的。
  • 当然好处是只能github账号登陆,坏处的话,issue会很乱吧。。。
  • 具体操作:可以看这里,就是先注册个application,然后把id、secret什么的填到next的config里就好。
  • 坑:Error:validation failed。原因是作者的方法在create an issue时,提交的id号太长了。。。方法是在next/_third-party/comments/gitment.swig里,修改id: window.location.pathnameid: '{{ page.date }}'

valine

  • 是我目前见到过的唯一支持匿名评论的,也是需要注册valine的账号

搜索

Swiftype

  • 去注册账号,拿到swiftype_key,写道next的配置里就好
  • 后来才这道这个是要收费的,不要用了

local search

  • npm install --save hexo-generator-search
  • 在主题的config里,local_search的enable要打开
  • 在hexo的config里,写上
1
2
3
search:
path: search.xml
field: post(或者all)
  • 最后hexo g就可以了

代码

  • 修改hexo的配置
1
2
3
4
5
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace:
  • 然后在next的配置里修改代码配色
1
highlight_theme: night bright
  • 写代码的时候,要注意在```后加上代码类型如c、python、yml等等

公式

  • 在next的config里,enable mathjax
  • 行内公式用$,行间公式用$$
  • 但是还有些问题,比如说公式里有两个_,hexo会优先按markdown给你解析成斜体,所以latex公式还不能直接抄,有些富豪需要转义
  • 当然,也有优雅的方法,换个render
1
2
npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save
  • 更换完了行内公式还是有问题,参考这里
  • 修改kramed的转义规则,文件为/node_modules/kramed/lib/rules/inline.js
1
2
escape: /^\\([`*\[\]()# +\-.!_>])/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
  • mathjax公式粗体,放弃\bm{},使用\boldsymbol{}

流程图

1
npm install --save hexo-filter-flowchart