Disqus在Jekyll博客中无法加载

3

我无法使Disqus在我的Jekyll博客中正常工作。我遵循了Disqus网站上的说明。我将评论添加到了文章布局中。

---
layout: default
comments: true
---
<h1>{{ page.title }}</h1>
<p>{{ page.date | date_to_string }} - {{ page.author }}</p>

{{ content }}

{% include disqus.html %}


使用 Disqus 网站生成的代码,添加 disqus.html。
{% if page.comments %}
<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.id }}; // 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 = 'https://rohit-gupta-blog.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>

{% endif %}


以下是翻译的结果:

这里是我网站上一个博客文章的例子文章。如果需要,这里是我的 Github 存储库。


也许 {% if page.comments %} 条件不起作用(它不是真的)。尝试暂时删除 {% if page.comments %} 和相关的 {% endif %} 进行验证。 - Tom Faltesek
仍然无法工作。但是我现在可以在页面源代码中看到脚本。 - Rohit Kumar Gupta
1个回答

0

看起来page.urlpage.url应该是字符串,但它们没有用引号括起来。这是在您页面上呈现的配置:

var disqus_config = function () {
  this.page.url = /blog/2020/01/15/rohit-gupta-blog-launched;
  this.page.identifier = /blog/2020/01/15/rohit-gupta-blog-launched;
};

这很可能是你想要的:

var disqus_config = function () {
  this.page.url = 'https://rohitkumargupta.com/blog/2020/01/15/rohit-gupta-blog-launched';
  this.page.identifier = '/blog/2020/01/15/rohit-gupta-blog-launched';
};

完整更新的disqus.html文件

<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 = 'https://rohitkumargupta.com{{ page.url }}';  // Replace PAGE_URL with your page's canonical URL variable
  this.page.identifier = '{{ page.id }}'; // 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 = 'https://rohit-gupta-blog.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>

谢谢您的帮助。您的解决方案“有效”,但我收到了一条消息“无法加载disqus”。 - Rohit Kumar Gupta
嘿@RohitKumarGupta。我认为Disqus期望page.url属性是您帖子的完整规范URL。尝试将协议和域添加到字符串中。我已更新我的答案。 - Tom Faltesek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接