Jekyll中的If Statement问题

时间:2016-01-17 14:50:57

标签: yaml jekyll github-pages

我在jekyll

中遇到if语句有困难
{% if site.disqus_account %}
<script type="text/javascript">
  /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
  function disqus_config() { this.experiment.enable_scroll_container = true; }
  var disqus_shortname = "{{ site.disqus_account }}"; // required: replace example with your forum shortname
  /* * * 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>
{% endif %}

以上代码功能齐全。我将disqus_account变量添加到我的yaml配置文件中,它运行正常。然而。如果我做site.com或post.com -

{% if site.disqus_account and site.comments %}
<script type="text/javascript">
  /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
  function disqus_config() { this.experiment.enable_scroll_container = true; }
  var disqus_shortname = "{{ site.disqus_account }}"; // required: replace example with your forum shortname
  /* * * 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>
{% endif %}

然后上面停止工作,没有显示任何内容。在我的帖子中,我宣布

---
layout: post
comments: true
---

我已多次重启我的jekyll服务器。编译我的网站时没有错误。为什么我要添加一个和语句来检查是否为该帖子启用了注释会阻止整个事情的加载?

我正在关注位于https://help.disqus.com/customer/portal/articles/472138-jekyll-installation-instructions的文章,以便设置disqus。

1 个答案:

答案 0 :(得分:0)

https://help.disqus.com/customer/portal/articles/472138-jekyll-installation-instructions引用的文章不正确。博客文章中声明的yaml变量位于page.comments而不是site.comments或post.comments。

相关问题