Skip to content

Fix bug with dynamic pages without pageProps and allow customizing the feed type object #5

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

Open
guillermodlpa opened this issue Sep 20, 2022 · 0 comments

Comments

@guillermodlpa
Copy link

Hi there!

I came across this library when I was searching for a way to build the RSS feed of my blog as part of the postbuild step, not in the getStaticProps function like I saw all tutorials out there suggesting. next-rss is great 🎉 because, like next-sitemap, is parsing the build manifest to obtain the list of blogs. That way, I don't need to query the API again to obtain the list.

However, I found an issue immediately. I suspect that when there are dynamic pages, like my case with /pages/blog/[blogPostSlug], it errors out because pageProps is undefined when looping through it as found in .next/server/pages/.... I'm not 100% positive that's the root cause, but it appears that the issue is fixed simply skipping the cases in which pageProps is undefined. See:

Screen Shot 2022-09-20 at 16 28 34

Adding these lines in src/feed.ts fixes the issue:

Screen Shot 2022-09-20 at 16 30 59

Additionally, I found myself wanting to add more properties in the feed items. Currently, next-rss only sets title, id, link and date, but library feed supports more parameters, like image, category, description and content, so it made sense to allow users to customize them.

Since I saw this project looked stale, I went ahead and made a fork to add the fix, a new feature of allowing to pass more item properties, and security fixes on the dependencies, so I could use it for my project. Here's the published version: https://www.npmjs.com/package/@guillermodlpa/next-rss

You can view here how the next-rss.js configuration ends up looking like with the new createFeedItem config parameter:

Screen Shot 2022-09-20 at 16 37 17

Source: https://github.com/guillermodlpa/site/blob/98669ef9fc4e9cbb35a528d3d1540ba1052e4dea/next-rss.js

The nice thing is that we can make next-rss adapt to the page props structure, as opposed to forcing next pages to use the structure defined internally in the package, as it is now.

If your next-rss project is active and maintained, let me know. I'd love to contribute pull requests with those changes and other useful functionality. I believe this library has a lot of potential.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant