Skip to content

Commit

Permalink
Use an if condition instead of slice
Browse files Browse the repository at this point in the history
  • Loading branch information
frankieroberto committed Oct 5, 2024
1 parent e4ceee2 commit e66ea68
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions layouts/feed.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,31 @@
<link href="{{ options.url }}"/>
<updated>{{ collections[collection] | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<id>{{ options.url }}/</id>
{%- for item in (collections[collection] | sort(true, false, "date") | slice(size)) %}
{%- set absolutePostUrl = item.url | canonicalUrl %}
<entry>
<title>{{ item.data.title }}</title>
<link href="{{ absolutePostUrl }}"/>
<updated>{{ item.date | dateToRfc3339 }}</updated>
<id>{{ absolutePostUrl }}</id>
{% if item.data.authors %}
{% for author in item.data.authors %}
{%- for item in (collections[collection] | sort(true, false, "date") %}
{%- if loop.index0 < size %}
{%- set absolutePostUrl = item.url | canonicalUrl %}
<entry>
<title>{{ item.data.title }}</title>
<link href="{{ absolutePostUrl }}"/>
<updated>{{ item.date | dateToRfc3339 }}</updated>
<id>{{ absolutePostUrl }}</id>
{% if item.data.authors %}
{% for author in item.data.authors %}
<author>
<name>{{ author.name }}</name>
{% if author.url %}<uri>{{ author.url }}</uri>{% endif %}
</author>
{% endfor %}
{% elif item.data.author %}
<author>
<name>{{ author.name }}</name>
{% if author.url %}<uri>{{ author.url }}</uri>{% endif %}
<name>{{ item.data.author.name }}</name>
{% if item.data.author.url %}<uri>{{ item.data.author.url }}</uri>{% endif %}
</author>
{% endfor %}
{% elif item.data.author %}
<author>
<name>{{ item.data.author.name }}</name>
{% if item.data.author.url %}<uri>{{ item.data.author.url }}</uri>{% endif %}
</author>
{% endif %}
<content xml:lang="{{ language or "en" }}" type="html">
<![CDATA[ {{ item.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }} ]]>
</content>
</entry>
{% endif %}
<content xml:lang="{{ language or "en" }}" type="html">
<![CDATA[ {{ item.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }} ]]>
</content>
</entry>
{%- endif %}
{%- endfor %}
</feed>

0 comments on commit e66ea68

Please sign in to comment.