【问题标题】:Why are code tags being inserted by liquid/jekyll and how do I remove them?为什么液体/jekyll 会插入代码标签,如何删除它们?
【发布时间】: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 %}

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:
    {% assign recent_leader = site.data.leaders[dedupped_leader] %}
    
            {{ recent_leader.name }}
            {{ recent_leader.bio }}
    

    如果你在 Markdown 文件中执行此操作,它将输出代码块 (see kramdown documentation)

    如果您不想要代码块,请执行:

    未缩进的行后没有换行符

    {% assign recent_leader = site.data.leaders[dedupped_leader] %}
        {{ recent_leader.name }}
        {{ recent_leader.bio }}
    

    两个空格缩进

    {% assign recent_leader = site.data.leaders[dedupped_leader] %}
    
      {{ recent_leader.name }}
      {{ recent_leader.bio }}
    

    【讨论】:

      猜你喜欢
      • 2016-05-04
      • 2020-07-13
      • 1970-01-01
      • 2019-02-14
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      相关资源
      最近更新 更多