使用无序列表按字母顺序对液体中的 .csv 数据进行排序会产生一个空列表元素

Sorting alphabetically .csv data in liquid using an unorderd list produces an empty list element

我已经设法按字母顺序显示我的 jekyll 网站的 .csv 文件中的数据,但我使用的代码只是在整个列表的开头添加了一个空的 <li> 标记.在我看来,"split" 过滤器负责输出的格式,所以可能有一些东西。

这是我在 liquid 中的代码:

---
layout: default
---
{% capture thelistings %}
  {% for listing in site.data.terminology %}
    {{ listing.term }}: {{ listing.definition }}
  {% endfor %}
{% endcapture %}
{% assign allsortedlistings = thelistings | split:"    " | sort %}

<ul>
{% for allterms in allsortedlistings %}
<li>{{ allterms }}</li>
{% endfor %}
</ul>

这里是 .csv 数据文件:

term,definition
brother,new explanation for one
aunt,another explanation for two
uncle,"and last one for three, with the use of comma fin"
father,this is it
again,now it is here
utah,this is a state
borrow,something from someone
forbidden,fruit

这是输出列表:

问题出在我输出数据的方式上。在执行第一个 {% capture %} 时,您必须按照希望输出的方式格式化数据,在这种情况下,我希望它是一个列表项,因此它应该看起来像这样 <li>{{ listing.term }}: {{ listing.definition }}</li>,从而将其包装在里面<li> 元素,然后在 <ul> 中将其指定为 {{ allterms }}。所以最终代码看起来像:

---
layout: default
---
{% capture thelistings %}
  {% for listing in site.data.terminology %}
    <li>{{ listing.term }}: {{ listing.definition }}</li>
  {% endfor %}
{% endcapture %}
{% assign allsortedlistings = thelistings | split:"   " | sort %}

    <ul>
{% for allterms in allsortedlistings %}
        {{ allterms }}
{% endfor %}
    </ul>