Hi!
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(value=page.date) %}
{% 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
Any help is very appreciated!