Sort RSS feed by updated date


I’d like to sort my RSS feed by updated date, but it turns out surprisingly hard to do.

First, the update field is null if it’s not set in a page preface (that’s expected, I guess?), so I can’t just do pages | sort(attribute="updated"). I need to populate the missing dates with created values.

So, I tried simply setting the missing dates:

{%- for page in pages %}
	{% set page.updated = page.updated | default( %}
{% endfor %}

This didn’t work because set only creates new variables; it can’t add values to hashmaps.

Next, I tried building a new map updated ⇒ page and then populating it with values that miss that date:

{% set_global by_update = pages | group_by(attribute="updated") %}
{% for page in pages %}
	{% if page.updated %}
		{% continue %}
	{% endif %}
	{% set_global by_update = by_update | concat(with=page) %}
{% endfor %}

But it didn’t work either since you can’t concat to a map.

I’m a bit lost. It seems like a simple task, but I can’t crack it :thinking:
Any help is very appreciated!

That’s because rss isn’t designed with “last updated” in mind and rather with a static sorting.
Even if you succeed with your goal and sort stuff by last updated, rss readers won’t be able to check for that.
You’re looking for an atom feed!

Sorry, I’m confusing those two. I’m actually doing this in atom.rss template, so it’s an atom feed.