Expected end_of_string but found pipe


#1

I am trying to install instant-articles.xml with jekyll-last-modified-at gem. When I bundle exec jekyll serve I get following warning.

Liquid Warning: Liquid syntax error (line 9): Expected end_of_string but found pipe in "post in site.posts | sort 'last_modified_at'" in instant-articles.xml

xml file is

---
layout: null
---

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>{{ site.name | xml_escape }}</title>
    <link>{{ site.url }}</link>
    <description>
      {% if site.description %}{{ site.description | xml_escape }}{% endif %}
    </description>
    {% for post in site.posts | sort 'last_modified_at' %}
    {% unless post.link %}
    <item>
      <title>{{ post.title | xml_escape }}</title>
      <link>{{ site.url }}{{ post.url }}</link>
      <content:encoded>
        <![CDATA[
        {{ post.content }}
        ]]>
      </content:encoded>
      <guid isPermaLink="false">{{ post.url }}</guid>
      <description>
        {% if post.excerpt %}
        {{ post.excerpt | xml_escape }}
        {% else %}
        {{ post.description | xml_escape }}
        {% endif %}
      </description>
      <pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
      <modDate>{{ post.last_modified_at | date: "%a, %d %b %Y %H:%M:%S %z" }}</modDate>
      <author></author>
    </item>
    {% endunless %}
    {% endfor %}
  </channel>
</rss>

#2

Have you tried using assign and applying the sort to that array? Sorting a for loop directly doesn’t generally work in my experience.

Try this instead:

{% assign posts = site.posts | sort 'last_modified_at' %}
{% for post in posts %}
    ...
{% endfor %}

#3

Thanks @mmistakes, it seems to be working