我最近将我的 Ghost 版本从 0.11.11 更新到 1.12.0
我还按照 Disqus - JavaScript configuration variables 添加了 PAGE_IDENTIFIER
索引页上的评论计数不反射(reflect)帖子评论。
这个link显示每个帖子的主页评论计数,特别是 Firefox 的帖子为 0 条评论
这个link显示 Disqus 评论数为 4 的 Firefox 帖子。
以下是我当前的评论脚本
<script type="text/javascript">
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var s = document.createElement('script');
s.async = true;
s.type = 'text/javascript';
s.src = '//' + disqus.shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
我使用以下内容创建评论计数链接
<i class="fa fa-comment-o"></i> <a href="{{url absolute="true"}}#disqus_thread" data-disqus-identifier="{{comment_id}}">Comments</a>
帖子评论脚本如下
<script type="text/javascript">
var disqus_config = function () {
this.page.url = '{{url absolute="true"}}';
this.page.identifier = '{{comment_id}}';
this.page.title = '{{title}}';
};
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = '//' + disqus.shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
问题
我最近使用映射器更新了 URL 链接,但这会获取新的 page.identifier
吗?
如果没有,我可以采取哪些步骤来修复评论计数?
调查
1. count.js
文件确实已加载,因为加载后链接文本已被替换。
2. 我发现加载 Disqus 计数脚本时会创建一个名为 DISQUSWIDGETS 的对象。 DISQUSWIDGETS.forum 字段未定义。
3. GitHub Gist 上的 jnowland 解构了 count.js文件,似乎必须定义 DISQUSWIDGETS.forum 才能设置正确的详细信息来检索计数。
最佳答案
根据 jnowland 的 count.js在 GitHub Gist 上的文件中,必须在执行 Disqus 评论计数脚本之前声明和定义 disqus_shortname
。
这将正确设置 DISQUSWIDGETS.forum 字段。
<script type="text/javascript">
var disqus_shortname = "MY_SHORTNAME"; // Replace MY_SHORTNAME with your DISQUS shortname.
/* * * DON'T EDIT BELOW THIS LINE * * */
(function () {
var s = document.createElement('script');
s.async = true;
s.type = 'text/javascript';
s.src = '//' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
关于javascript - Ghost 1.0 Disqus 评论数未反射(reflect)帖子评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46638874/