Ghost上安装Disqus插件

以下内容以Ghost-0.10,Casper-1.3.1 为例,其他版本可能会略有差异,请自行调整。

1. 找到 post.hbs 模版文件所在

例如:yourghostdir/content/themes/casper/post.hbs

2. 从disqus上找到你自己站点的代码

可以从这里找到你自己主站的代码:

Home => Settings => Installation => Universal Code  

3. 添加评论框

编辑 post.hbs, 将评论框的代码插入到 </footer></article> 标签的中间:

        </footer>

<div id="disqus_thread"></div>  
<script>

/**
 *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
 *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables */
/*
var disqus_config = function () {  
    this.page.url = PAGE_URL;  // Replace PAGE_URL with your page's canonical URL variable
    this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
*/
(function() { // DON'T EDIT BELOW THIS LINE
    var d = document, s = d.createElement('script');
    s.src = '//your-site.disqus.com/embed.js';
    s.setAttribute('data-timestamp', +new Date());
    (d.head || d.body).appendChild(s);
})();
</script>  
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

    </article>

disqus_config 我们可以不用设置,disqus会根据url来管理你的评论。

4. 文章列表显示评论数

编辑 default.hbs, 将评论数的代码粘贴到</body>的前面即可:

    <script id="dsq-count-scr" src="//your-site.disqus.com/count.js" async></script>

</body>  

然后编辑 partials/loop.hbs 找到 post-meta footer标签段落,插入相应的评论数代码片段:

    <footer class="post-meta">
        {{#if author.image}}<img class="author-thumb" src="{{author.image}}" alt="{{author.name}}" nopin="nopin" />{{/if}}
        {{author}}
        {{tags prefix=" on "}}
        <time class="post-date" datetime="{{date format="YYYY-MM-DD"}}">{{date format="DD MMMM YYYY"}}</time>
        (<a href="{{url}}#disqus_thread">Comments</a>)
    </footer>