Skip to content

Commit

Permalink
Merge pull request #23 from pedromaltez/support-single-item-feed
Browse files Browse the repository at this point in the history
Add support for single item feeds
  • Loading branch information
nasa8x authored Oct 6, 2020
2 parents e2b3a61 + aa83f93 commit 2c1ab04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ module.exports = {
rss.image = channel['itunes:image'].href;
}

if(items && !Array.isArray(items)) {
// the main 'items' code block below expects the items variable to be an Array of Objects
// but if in the originating XML the channel element contains only a single item, the items
// variable is set to a literal Object instead of an Array of Objects of length 1. It is fixed
// here so the items variable behaves the same whether it contains 1 or many items
items = [items];
}

if (items && items.length > 0) {

for (let i = 0; i < items.length; i++) {
Expand Down

0 comments on commit 2c1ab04

Please sign in to comment.