使用disqus搭建comment时一件很二的事

来源:互联网 发布:淘宝客网站 编辑:程序博客网 时间:2024/04/28 03:28

最近在github 上面搭建自己的博客,搭建comment部分的时候出现了一个问题:配置都配置好了,但是comment就是不成功。昨天为这个问题折腾了了半晚上没找出原因,今天晚上我突然发现一个地方设置有点不是很常规,改了后发现Okay了,comment模块可以成功运转了,高兴,同时也为自己犯的低级错误而无奈。

一、先说说搭建disqus的一些基本配置:

1. 在_config.yml中配置如下图:


update:

使用disqus得注册一个disqus账号,并在disqus里面将你的域名添加进去,并设置一个上面的short_name。

2. 为了加快网页的渲染速度,我们决定在需要的时候在加载comment这个部分。在模板代码中(post.html)文章的最后添加如下代码:

<div class="main-container shadow">   <div class="mainbody">     <button class="btn-primary btn-small" id="show_disqus">Show Comments</button>     <script type="text/javascript">       $(function() {         $('#show_disqus').click(function() {           var s = '<div id="disqus_thread"></div><script type="text/javascript">';           s += '{% if site.safe == false %}var disqus_developer = 1;{% endif %}';           s += "var disqus_shortname = '{{ site.JB.comments.disqus.short_name }}';";           s += "{% if page.wordpress_id %}var disqus_identifier = '{{page.wordpress_id}} {{site.production_url}}/?p={{page.wordpress_id}}';{% else %} var disqus_identifier = '{{ page.url }}';{% endif %}";           s += "var disqus_url = '{{ site.production_url }}{{ page.url }}';"           s += "(function() {var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);})();";           s += '</' + 'script>';           $('#show_disqus').after('<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>').after('<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>').after(s).hide();         });       });     </script>   </div> </div>

二、我犯的低级的错误:

犯的错误在_config.yml中配置production_url是链接没有加http这个前缀,因为这个导致comment模块不能正常的工作。所以以后再配置url的时候应该尽量写全,是http的就要写成http://…..,是https的就要写成https://…这个标准的东西能减少你很多无效时间的消耗。

如果你觉得本篇对你有收获,请帮顶。
另外,我开通了微信公众号--分享技术之美,我会不定期的分享一些我学习的东西.
你可以搜索公众号:swalge 或者扫描下方二维码关注我

(转载文章请注明出处: http://blog.csdn.net/swagle/article/details/28303169 )
7 0
原创粉丝点击