Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix feed by not using pagination #333

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions docs/feed.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ To create a feed, add a file named `feed.njk` with the following content:
eleventyExcludeFromCollections: true
layout: feed
permalink: /feed.xml
pagination:
data: collections.post
size: 20
reverse: true
collection: post
size: 20
---
```

The `permalink` value is the location of the generated feed.

## Create a collection of pages

The feed will include all pages in the collection referenced by the `data` key of the `pagination` object.
The feed will include pages in the collection referenced in the `collection` key, up to a maximum specified in `size`, with the newest first.

You can create a collection by adding some code to your `eleventy.config.js`:

Expand Down
46 changes: 23 additions & 23 deletions layouts/feed.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
<title>{{ options.homeKey }}</title>
<link href="{{ permalink | canonicalUrl }}" rel="self"/>
<link href="{{ options.url }}"/>
<updated>{{ collections.post | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
<id>{{ options.url }}/</id>
{%- for item in pagination.items %}
{%- 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] %}
{%- if loop.index0 < size %}
{%- set absolutePostUrl = item.url | canonicalUrl %}
<entry>
<title>{{ item.data.title }}</title>
<link href="{{ absolutePostUrl }}"/>
<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>