comparison js/feed-parser.js @ 31:76e23b361e92

Allow feed reader addons to subscribe to the currently viewed feed Add a link element to the feed preview that points to the currently viewed feed in order to allow feed reader addons to subscribe to it.
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Tue, 22 Jan 2019 14:40:06 +0100
parents 104a1faebd43
children b68880838990
comparison
equal deleted inserted replaced
30:b9dc94ce2eeb 31:76e23b361e92
182 return this._content; 182 return this._content;
183 } 183 }
184 } 184 }
185 185
186 class Feed { 186 class Feed {
187 constructor(url, {title = browser.i18n.getMessage('defaultFeedTitle'), 187 constructor(url, type, {title = browser.i18n.getMessage('defaultFeedTitle'),
188 subtitle = '', logo, entries = []} = {}) { 188 subtitle = '', logo, entries = []} = {}) {
189 this.url = url; 189 this.url = url;
190 this.type = type;
190 this.title = title; 191 this.title = title;
191 this.subtitle = subtitle; 192 this.subtitle = subtitle;
192 this.logo = logo; 193 this.logo = logo;
193 this.entries = entries; 194 this.entries = entries;
194 } 195 }
429 './atom03:entry'); 430 './atom03:entry');
430 for (let entryElement of entryElements) { 431 for (let entryElement of entryElements) {
431 entries.push(this.parseAtom03Entry(entryElement)); 432 entries.push(this.parseAtom03Entry(entryElement));
432 } 433 }
433 434
434 return new Feed(this.url, {title, subtitle, logo, entries}); 435 return new Feed(this.url, 'application/atom+xml',
436 {title, subtitle, logo, entries});
435 } 437 }
436 438
437 parseAtomLogo(logoElement) { 439 parseAtomLogo(logoElement) {
438 let url = parseURL(logoElement.textContent.trim(), this.url); 440 let url = parseURL(logoElement.textContent.trim(), this.url);
439 if (url === null) { 441 if (url === null) {
593 './atom:entry'); 595 './atom:entry');
594 for (let entryElement of entryElements) { 596 for (let entryElement of entryElements) {
595 entries.push(this.parseAtomEntry(entryElement)); 597 entries.push(this.parseAtomEntry(entryElement));
596 } 598 }
597 599
598 return new Feed(this.url, {title, subtitle, logo, entries}); 600 return new Feed(this.url, 'application/atom+xml',
601 {title, subtitle, logo, entries});
599 } 602 }
600 603
601 parseRSS1Logo(imageElement, nsPrefix) { 604 parseRSS1Logo(imageElement, nsPrefix) {
602 let title; 605 let title;
603 let urlElement = feedQueryXPath(this.document, imageElement, 606 let urlElement = feedQueryXPath(this.document, imageElement,
675 if (typeof entry !== 'undefined') { 678 if (typeof entry !== 'undefined') {
676 entries.push(entry); 679 entries.push(entry);
677 } 680 }
678 } 681 }
679 682
680 return new Feed(this.url, {title, subtitle, logo, entries}); 683 return new Feed(this.url, 'application/rss+xml',
684 {title, subtitle, logo, entries});
681 } 685 }
682 686
683 parseRSS2Logo(imageElement) { 687 parseRSS2Logo(imageElement) {
684 let title; 688 let title;
685 let urlElement = feedQueryXPath(this.document, imageElement, './url'); 689 let urlElement = feedQueryXPath(this.document, imageElement, './url');
803 if (typeof entry !== 'undefined') { 807 if (typeof entry !== 'undefined') {
804 entries.push(entry); 808 entries.push(entry);
805 } 809 }
806 } 810 }
807 811
808 return new Feed(this.url, {title, subtitle, logo, entries}); 812 return new Feed(this.url, 'application/rss+xml',
813 {title, subtitle, logo, entries});
809 } 814 }
810 815
811 parseFromString(xmlString, url) { 816 parseFromString(xmlString, url) {
812 this.url = url; 817 this.url = url;
813 this.document = new DOMParser().parseFromString(xmlString, 818 this.document = new DOMParser().parseFromString(xmlString,