Next主题 多说embed.js本地化

看完多说评论不稳定,加载速度慢优化方法一篇文章,自己也试去对自己的next进行修改,但仅仅是为了获取多说embed.js的CDN而还要去注册七牛镜像,这是我自己不愿意的,所以退而求其次,实现本地化也是可以大大的提高多说评论加载速度的。以下就是我的操作过程。

修改duoshuo.swig

找到到themes/next/layout/_scripts/third-party/comments/duoshuo.swig文件

删除文件中的

1
2
3
4
5
6
7
8
9
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.id = 'duoshuo-script';
ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementById('footer')
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();

然后在

1
{% if theme.duoshuo_info.ua_enable %}

前加上

1
2
3
{% if (theme.duoshuo and theme.duoshuo.shortname) or theme.duoshuo_shortname %}
<script src="{ { url_for(theme.js) } }/src/embed.js"></script>
{% endif %}

其中embed.js就是多说的embed.js代码

获取embed.js

浏览器访问http://static.duoshuo.com/embed.js,拷贝保存我就不说了,保存的路径保持和<script src="{ { url_for(theme.js) } }/src/embed.js"></script>中的路径一直就可以了。

由于hexo标签导致hexo g报错,无法生成页面,所以文章中被替换成了{ {