comparison js/feed-parser.js @ 47:b68880838990

Add support for the RSS Content module to the RSS 2.0 feed parser
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Wed, 03 Jul 2019 16:57:17 +0200
parents 76e23b361e92
children d5506fdb65f0
comparison
equal deleted inserted replaced
46:586eebf8efb7 47:b68880838990
11 export const XMLNS = { 11 export const XMLNS = {
12 ATOM03: 'http://purl.org/atom/ns#', 12 ATOM03: 'http://purl.org/atom/ns#',
13 ATOM10: 'http://www.w3.org/2005/Atom', 13 ATOM10: 'http://www.w3.org/2005/Atom',
14 RSS09: 'http://my.netscape.com/rdf/simple/0.9/', 14 RSS09: 'http://my.netscape.com/rdf/simple/0.9/',
15 RSS10: 'http://purl.org/rss/1.0/', 15 RSS10: 'http://purl.org/rss/1.0/',
16 CONTENT: 'http://purl.org/rss/1.0/modules/content/',
16 XHTML: 'http://www.w3.org/1999/xhtml', 17 XHTML: 'http://www.w3.org/1999/xhtml',
17 PARSERERROR: 'http://www.mozilla.org/newlayout/xml/parsererror.xml' 18 PARSERERROR: 'http://www.mozilla.org/newlayout/xml/parsererror.xml'
18 } 19 }
19 const ALLOWED_LINK_PROTOCOLS = new Set(['http:', 'https:', 'ftp:']); 20 const ALLOWED_LINK_PROTOCOLS = new Set(['http:', 'https:', 'ftp:']);
20 21
73 return XMLNS.ATOM10; 74 return XMLNS.ATOM10;
74 case 'rss09': 75 case 'rss09':
75 return XMLNS.RSS09; 76 return XMLNS.RSS09;
76 case 'rss10': 77 case 'rss10':
77 return XMLNS.RSS10; 78 return XMLNS.RSS10;
79 case 'content':
80 return XMLNS.CONTENT;
78 } 81 }
79 return null; 82 return null;
80 } 83 }
81 84
82 function feedQueryXPath(feedDocument, scopeElement, xpathQuery) { 85 function feedQueryXPath(feedDocument, scopeElement, xpathQuery) {
747 './pubDate'); 750 './pubDate');
748 if (pubDateElement !== null) { 751 if (pubDateElement !== null) {
749 date = parseDate(pubDateElement.textContent); 752 date = parseDate(pubDateElement.textContent);
750 } 753 }
751 754
752 let descriptionElement = feedQueryXPath(this.document, itemElement, 755 let encodedElement = feedQueryXPath(this.document, itemElement,
753 './description'); 756 './content:encoded');
754 if (descriptionElement !== null) { 757 if (encodedElement !== null) {
755 content = descriptionElement.textContent.trim(); 758 content = encodedElement.textContent.trim();
759 } else {
760 let descriptionElement = feedQueryXPath(this.document, itemElement,
761 './description');
762 if (descriptionElement !== null) {
763 content = descriptionElement.textContent.trim();
764 }
756 } 765 }
757 766
758 for (let enclosureElement of 767 for (let enclosureElement of
759 feedQueryXPathAll(this.document, itemElement, './enclosure')) { 768 feedQueryXPathAll(this.document, itemElement, './enclosure')) {
760 try { 769 try {