Jekyll博客中series.html中的If语句

Jekyll博客中series.html中的If语句,jekyll,Jekyll,我在我的jekyll博客的_includes部分的series.html文件中有一些语言,粘贴在下面: {% if page.series %} {% assign count = '0' %} {% assign idx = '0' %} {% for post in site.posts reversed %} {% if post.series == page.series %} {% capture count %}{{ count | plus: '1' }}{

我在我的jekyll博客的_includes部分的series.html文件中有一些语言,粘贴在下面:

{% if page.series %}
{% assign count = '0' %}
{% assign idx = '0' %}
{% for post in site.posts reversed %}
    {% if post.series == page.series %}
        {% capture count %}{{ count | plus: '1' }}{% endcapture %}
        {% if post.url == page.url %}
            {% capture idx %}{{count}}{% endcapture %}
        {% endif %}
    {% endif %}
{% endfor %}
{% endif %}
虽然它确实连接了在帖子的YAML布局中被指定为一系列的帖子,但它也连接了作为一系列的一部分的其他帖子,即使它们在帖子的YAML前端没有被指定为“系列”,尽管有if声明。这导致我所有的文章都是我不想要的一般“系列”的一部分。我只想把一些帖子指定为一个系列的一部分,而另一些只是独一无二的一次性帖子

我尝试了以下方法:

  • 在YAML前端中根本不指定序列
  • 设置系列:错误
  • 设置系列:无

  • 编辑:

    模板中实际发生的情况是,并非所有html都是有条件打印的

    \u includes/series.html中的所有内容都受
    page.series!=null,但始终打印
    的内容

    您需要在\u includes/series.html中移动此代码(所有
    […]

    {% if page.series != null %}
    [...]
    {% endfor %}
    <div class="panel seriesNote">  <<<< moved code
    [...]
    </div>                          <<<< end moved code
    {% endif %}
    
    {%if page.series!=null%}
    [...]
    {%endfor%}
    count是一个字符串

    {%capture count%}{{count | plus:1}{%endcapture%}
    =>count是一个字符串

    如果您这样做:

    {%assign count=0%}=>count是一个整数

    {%assign count=count | plus:1%}=>count是一个整数


    当您在比较中使用计数器时,请注意这一点,尝试比较字符串和整数可能会导致错误。

    我已按照建议将_includes文件夹中的series.html文件中的
    {%if page.series%}
    更改为
    {%if page.series!=null%}
    ,YAML中未设置序列的柱以某种方式连接到其他未设置YAML序列的柱。其他想法?你有存储库url吗?这可能会有所帮助。根据你的兴趣水平,我在我的个人资料中发布了两个与我的jekyll博客相关的问题。对于精通jekyll和liquid的人,我怀疑他们很容易回答。我包括了您建议的代码:
    {%if page.series!=null%}{%assign count='0'%}{%assign idx='0'%}{%for site中的post.posts reversed%}{%if post.series==page.series%}{%capture count%}{{count}加上:'1'}{%endcapture%}{%if post.url==page.url%}{%capture idx%}{count}{%endcapture%}{%endif%}{%endif%}{%endif%}{%endfor%}{%endif%}
    但它仍在链接“未序列化”帖子。它还具有删除我的相关帖子的附加效果。做得好-做到了。谢谢你的耐心和指导。看起来很棒。