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

Feed breaks if there are more posts than the pagination size #330

Open
frankieroberto opened this issue Sep 20, 2024 · 2 comments · May be fixed by #333
Open

Feed breaks if there are more posts than the pagination size #330

frankieroberto opened this issue Sep 20, 2024 · 2 comments · May be fixed by #333
Labels
bug Something isn't working

Comments

@frankieroberto
Copy link
Contributor

If you follow the instructions for feeds but have more posts in the feed than specified in the pagination size, it breaks with the error message:

Output conflict: multiple input files are writing to `_site/posts/feed.xml`. Use distinct `permalink` values to resolve this conflict.
[11ty]   1. ./app/feed.njk
[11ty]   2. ./app/feed.njk (via DuplicatePermalinkOutputError)

Need to find a way to only include the most recent x items in the feed rather than one file per page.

@paulrobertlloyd paulrobertlloyd added the bug Something isn't working label Sep 21, 2024
@paulrobertlloyd
Copy link
Collaborator

Ah, this is probably why we didn’t use pagination in the first place; it’s going to try and create a second file, also called feed.xml.

Why did we move to using pagination again? Anyway, I think the feed.njk layout will need to be reverted, to something more along the lines of

- {%- for item in pagination.items %}
+ {%- for item in collections.post | limit: size | reverse %}

And the documentation updated to use the following front matter:

---
eleventyExcludeFromCollections: true
layout: feed
permalink: /feed.xml
size: 20
---

I note that we’re using collections.post in that template anyway, so the collection to pull items from was never truly configurable. We can keep it so that you can use a different collection, with something like this:

-   <updated>{{ collections.post | getNewestCollectionItemDate | dateToRfc3339 }}</updated>
+   <updated>{{ collections[collection] | getNewestCollectionItemDate | dateToRfc3339 }}</updated>

- {%- for item in pagination.items %}
+ {%- for item in collections[collection] | limit: size | reverse %}

And use the following front matter:

---
eleventyExcludeFromCollections: true
layout: feed
permalink: /feed.xml
collection: posts
size: 20
---

Want to try that?

frankieroberto added a commit that referenced this issue Sep 24, 2024
I think this should resolve #330 but need to test it somehow.
@frankieroberto frankieroberto linked a pull request Sep 24, 2024 that will close this issue
@frankieroberto
Copy link
Contributor Author

Ah, this is probably why we didn’t use pagination in the first place; it’s going to try and create a second file, also called feed.xml. Why did we move to using pagination again?

Yeah, I can’t remember. Maybe it was just to specify the collection (so you could have multiple feeds) or size. But, err, clearly didn’t think ahead to what happens when you overflow the size.

I guess it could be fixed by using a permalink like this:

permalink: "feed{{ "" if pagination.pageNumber == 0 else pagination.pageNumber }}.xml"

...but it's not really necessary to paginate your rss feeds.

Your suggestion sounds better. Have tried it in #333 - although limit: size doesn’t work so used slice instead. Also couldn't remember if collections are reliably already in date order, or if they need to be sorted using the date?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants