Jekyll:检查帖子内容是否为空

Pte*_*aur 8 ruby liquid jekyll

我在Jekyll项目中有一系列帖子,其中一些只有一个标题,一些有标题和内容.我想在每种情况下用帖子做不同的事情.例如:

{% for post in site.categories.publications %}
    {{ post.title }}
    {% if post.content == "" or post.content == nil or post.content == blank %}
        <p>Nothing here.</p>
    {% else %}
        {{ post.content }}
    {% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

但该if声明实际上并没有抓住空帖.我根据这个页面的条件,但3个可能性中没有一个抓住空帖.关于如何处理这些帖子的任何想法?

Dav*_*uel 10

事前你确定没有任何东西

---
---
NO NEW LINE HERE !!
Run Code Online (Sandbox Code Playgroud)

没有空间,没有新线

有时文本编辑器会在文件末尾添加换行符.你可以用以下方法摆脱它:

{% assign content = post.content | strip_newlines %}
Run Code Online (Sandbox Code Playgroud)

然后测试:

{% if content == ""  %}
Run Code Online (Sandbox Code Playgroud)