配置Hexo使用Mathjax,以及开启访问统计和配置评论

本文转载自:xiholix博客

1. 使用Kramed代替 Marked

在工程目录下(即hexo init执行的那个目录下)执行以下命令安装Kramed

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

然后将/node_modules/hexo-renderer-kramed/lib/renderer.js中的内容按如下方式修改:

更改前:
// Change inline math rule
function formatText(text) {
    // Fit kramed's rule: $$ + \1 + $$
    return text.replace(/`\$(.*?)\$`/g, '$$$$$1$$$$');
}
更改后:
// Change inline math rule
function formatText(text) {
    return text;
}

2. 停止使用hexo-math,安装 hexo-renderer-mathjax

命令如下:

npm uninstall hexo-math --save
npm install hexo-renderer-mathjax --save

3. 更新 Mathjax 的 CDN 链接

将/node_modules/hexo-renderer-mathjax/mathjax.html中的CDN链接更改为下面的链接

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>

4. 修改hexo的默认转义规则

打开/nodes_modules/marked/lib/marked.js文件对其进行如下几项修改

更改前
escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

更改后:
escape: /^\\([`*\[\]()# +\-.!_>])/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,

5. 开启mathjax

在主题的_config.yml中添加(如果不存在)或修改(如果存在)mathjax配置

mathjax:
    enable: true

6. 安装next主题并配置Next.Mist

在项目根目录执行如下git命令,安装Next主题

git clone https://github.com/iissnan/hexo-theme-next themes/next
cd themes/next
git pull

在根目录的_config.yml更改主题配置

theme: next

在themes/next下的_config.yml更改Mist配置

scheme: Muse
更改为
scheme: Mist

7. 网站底部加上访问量(使用busuanzi)

在themes/next里的_config.yml将busuanzi的统计打开

busuanzi_count:
  # count values only if the other configs are false
  enable: true

8.配置评论(使用Valine和Leancloud)

首先注册Leanclout账号注册链接,创建一个应用,并获取其appkey和appid
然后修改themes/next下的_config.yml的对应配置

valine:
  enable: true
  appid:  # your leancloud application appid
  appkey:  # your leancloud application appkey

9.开启分享功能(jiathis)

编辑themes/next下的_config.yml

jiathis: true
  ##uid: Get this uid from http://www.jiathis.com/
#add_this_id:

10. 与github链接

首先将电脑的ssh公钥加入到github账号中,然后配置项目根目录下的_config.yml

deploy:
  type: git
  repository: git@github.com:usrname/username.github.io.git
  branch: master

11. 配置搜索功能

在项目根目录执行如下命令安装相应组件

npm install hexo-generator-searchdb --save

修改站点配置文件,添加如下配置

search:
    path: search.xml
    field: post
    format: html
    limit: 10000

修改主题配置文件

local_search:
    enable: true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值