【发布时间】:2015-02-05 01:18:12
【问题描述】:
我想为我正在使用 Jekyll 开发的博客创建一个最近作者的列表。
我正在获取最近作者的列表,并在我设置的 yml 数据表中查找每个项目,其中列出了每个作者及其简历、姓名和电子邮件等。
我能够提取我想要的信息,但是当它在浏览器中呈现时,它位于<code> 标记之间。
问题位是
{% assign recent_leader = site.data.leaders[dedupped_leader] %}
{{ recent_leader.name }}
{{ recent_leader.bio }}
assign 语句似乎将整个循环内容放入一个代码块中。
如何摆脱<code> 标签?我想知道是否只是某个地方的逗号不合适或......
这是页面的其余代码。
{% comment %}First loop captures leaders from the last three months {% endcomment %}
{% for post in site.posts %}
{% capture postDateSeconds %}{{post.date | date: "%s"}}{% endcapture %}
{% capture siteTimeMinusTwelveWeeks %}{{site.time | date: "%s" | minus: 7260000}}
{% endcapture %}
{% if postDateSeconds >= siteTimeMinusTwelveWeeks and post.date <= site.time %}
{% capture indexes %}{{ indexes | append: forloop.index | append: "," }}{% endcapture %}
{% capture leaders %}{{ leaders | append: post.leader | append: "," }}{% endcapture %}
{% endif %}
{% endfor %}
{% comment %}Split the captured loop into its own array {% endcomment %}
{% assign leaders_array = leaders | split: "," %}
{% comment %} initialise a new array for dedupped list{% endcomment %}
{% assign dedupped_leaders = "" %}
{% comment %} if the leaders name is in the new array already remove it. Then add the name. This makes sure the name is on the list just once. {% endcomment %}
{% for leader in leaders_array %}
{% if dedupped_leaders contains leader %}
{% assign leader_and_comma = leader | append: "," %}
{% capture dedupped_leaders %}{{dedupped_leaders | remove_first: leader_and_comma }}{% endcapture %}
{% endif %}
{% capture dedupped_leaders %}{{dedupped_leaders | append: leader | append: ","}}{% endcapture %}
{% endfor %}
{% comment %}Split the captured loop into its own array {% endcomment %}
{% assign dedupped_leaders_array = dedupped_leaders | split: "," %}
{% for dedupped_leader in dedupped_leaders_array %}
{% assign recent_leader = site.data.leaders[dedupped_leader] %}
{{ recent_leader.name }}
{{ recent_leader.bio }}
{% endfor %}
【问题讨论】: