11ty / eleventy-plugin-rss

A pack of Eleventy plugins for generating an RSS feed.
https://www.11ty.dev/docs/plugins/rss/
MIT License
92 stars 23 forks source link

Suggestion: Silently fail when using rssLastUpdatedDate filter #1

Closed bigredwill closed 3 years ago

bigredwill commented 5 years ago

I want to include an rss feed on a new project and have the site build without any posts. The rssLastUpdatedDate njk filter currently throws an error when the posts collection is empty and causes the build to fail.

https://github.com/11ty/eleventy-plugin-rss/blob/34cb9f077cac9b104730bb9d56e4ab6ec143775f/.eleventy.js#L9

My suggestion is to not throw an error when the user has no posts and instead output a null value.

I can make the change if we agree that this is a desirable behavior.

zachleat commented 5 years ago

Sorry for the late reply here.

Hmm, yes I like where you’re going here @bigredwill.

If you look at where it might be used though, for example in our Atom feeds in the eleventy-base-blog project (https://github.com/11ty/eleventy-base-blog/blob/master/feed/feed.njk#L10). Also at https://github.com/11ty/eleventy-plugin-rss/blob/master/sample/feed.njk#L22

I don’t think an empty updated element in the Atom feed is allowed.

See https://validator.w3.org/feed/docs/atom.html and Required feed elements.

If we switch this to return a null value, I think we’d also want to change the upstream usage above to fallback to a file creation date if the collection is empty.

thecristen commented 4 years ago

I got this error after I deleted an existing post via Netlify CMS, so that's a not fun side effect of throwing an error here.

ryan-mahoney commented 3 years ago

@thecristen fancy running into you here :)

I also hit this error today while trying to enable the RSS feed on a fairly vanilla eleventy site.

After doing some logging, I could see that my collections global variable does not contain a key named posts. It did however have all, and changing collections.posts to collections.all in my feed.njk file resolved this issue.

Wondering if this is a documentation issue or a configuration issue on my end. At a minimum, I think the documentation for this plugin might want to offer some hints about where you might find your posts in the collection.

zachleat commented 3 years ago

Changed my mind here—in v1.1.0 empty collections will no longer throw an error—as a fallback we’ll just return the current Date instead.

Beginning in 1.1.0 you can pass in your own fallback date as the second argument to the filter if you’d like, though I’d be surprised if that’s necessary!