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 issue #269: Library returning incorrect href #276

Closed
wants to merge 2 commits into from
Closed
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
25 changes: 24 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,35 @@ class Parser {
return prom;
}

getFeedUrl(links) {
if (!Array.isArray(links)) {
links = [links];
}

for (let link of links) {
if (link.$ && link.$.rel === 'self' &&
(link.$.type === 'application/rss+xml' || link.$.type === 'application/atom+xml')) {
return link.$.href;
}
}

// If no suitable link is found, fall back to the first link with rel="self"
for (let link of links) {
if (link.$ && link.$.rel === 'self') {
return link.$.href;
}
}

// If still no suitable link is found, return the href of the first link
return links[0] && links[0].$ ? links[0].$.href : null;
}

buildAtomFeed(xmlObj) {
let feed = {items: []};
utils.copyFromXML(xmlObj.feed, feed, this.options.customFields.feed);
if (xmlObj.feed.link) {
feed.link = utils.getLink(xmlObj.feed.link, 'alternate', 0);
feed.feedUrl = utils.getLink(xmlObj.feed.link, 'self', 1);
feed.feedUrl = this.getFeedUrl(xmlObj.feed.link);
}
if (xmlObj.feed.title) {
let title = xmlObj.feed.title[0] || '';
Expand Down
Loading