Jekyll网站的RSS源,在Liquid中生成 - 由于项目中的HTML而导致验证失败

时间:2015-02-12 11:33:40

标签: xml rss jekyll liquid

我在Jekyll中构建了一个RSS feed。现在,当我在YAML前端使用html时,RSS源会崩溃。我以为xml_escape会解决这个问题。有什么我可以做的,或者我是否需要删除HTML。

---
layout: null
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>{{ site.title | xml_escape }}</title>
    <description>{{ site.description | xml_escape }}</description>
    <language>en</language>
    <copyright>Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)</copyright>
    <link>{{ site.url }}{{ site.baseurl }}/</link>
    <atom:link href="{{ "/meetingsfeed.xml" | prepend: site.baseurl | prepend: site.url }}" rel="self" type="application/rss+xml"/>
    <pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
    <lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
    <generator>Jekyll v{{ jekyll.version }}</generator>
    {% for post in site.posts reversed limit: 8%}
    {% if post.date >= site.time %}
      <item>
        {%if post.title %}
        <title>{{ post.title | xml_escape }}</title>
        {% else %}
        <title>TBC</title>
        {% endif %}
        {% if post.meeting_blurb %}
        <description>{{ post.meeting_blurb | xml_escape }}</description>
        {% endif %}
        <pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
        <link>{{ post.url | prepend: site.baseurl | prepend: site.url }}</link>
        {% if post.title == blank or post.title == nil or post.title contains "Tbc" or post.title contains "tbc" or post.title contains "TBC" %}
        <guid  isPermaLink="false">{{ post.url | prepend: site.baseurl | prepend: site.url }}</guid>
        {% else %}
        <guid isPermaLink="true">{{ post.url | prepend: site.baseurl | prepend: site.url }}</guid>
        {% endif %}
        {% for tag in post.tags %} <category>{{ tag | xml_escape }}</category> {% endfor %}
        {% for cat in post.categories %}<category>{{ cat | xml_escape }}</category>{% endfor %}
        {% if post.leader %} {% assign leader = site.data.leaders[post.leader] %}
               <dc:creator>{{leader.name | xml_escape }}</dc:creator>
        {% else %}
               <dc:creator>Volunteer to lead this meeting</dc:creator>

        {% endif %} 
      </item>
     {% endif %} 
    {% endfor %}
  </channel>
</rss>

导致问题的项目是:

<item>
<title>
Four Noble Truths &ndash; third and fourth truths (with reference to the book by Ajahn Sumedho)
</title>
<description>
Ajahn Sumedho's book <a href="http://forestsanghapublications.org/viewBook.php?id=32&ref=deb"><i>Four Noble Truths</i></a> is available to read online.
</description>
<pubDate>Wed, 04 Mar 2015 19:30:00 +0000</pubDate>
<link>
http://www.bodhinyanagroup.org.uk/2015/03/04/four-noble-truths.html
</link>
<guid isPermaLink="true">
http://www.bodhinyanagroup.org.uk/2015/03/04/four-noble-truths.html
</guid>
<dc:creator>Simon Hall</dc:creator>
</item>

说明中的ndash和链接存在问题。

1 个答案:

答案 0 :(得分:2)

这里有两个解决方案:

<description>{{ post.meeting_blurb | escape }}</description>

<description><![CDATA[{{ post.meeting_blurb }}]]></description>