Mercurial > addons > firefox-addons > feed-preview
changeset 48:d5506fdb65f0
Add support for Dublin Core elements to the RSS 2.0 feed parser
author | Guido Berhoerster <guido+feed-preview@berhoerster.name> |
---|---|
date | Fri, 05 Jul 2019 13:29:29 +0200 |
parents | b68880838990 |
children | f4e8aa4d50da |
files | js/feed-parser.js |
diffstat | 1 files changed, 46 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/js/feed-parser.js Wed Jul 03 16:57:17 2019 +0200 +++ b/js/feed-parser.js Fri Jul 05 13:29:29 2019 +0200 @@ -14,6 +14,7 @@ RSS09: 'http://my.netscape.com/rdf/simple/0.9/', RSS10: 'http://purl.org/rss/1.0/', CONTENT: 'http://purl.org/rss/1.0/modules/content/', + DC: 'http://purl.org/dc/elements/1.1/', XHTML: 'http://www.w3.org/1999/xhtml', PARSERERROR: 'http://www.mozilla.org/newlayout/xml/parsererror.xml' } @@ -78,6 +79,8 @@ return XMLNS.RSS10; case 'content': return XMLNS.CONTENT; + case 'dc': + return XMLNS.DC; } return null; } @@ -735,8 +738,16 @@ let date; let content; let files = []; - let titleElement = feedQueryXPath(this.document, itemElement, - './title'); + let titleElement; + let dateElement; + let contentElement; + + titleElement = feedQueryXPath(this.document, itemElement, + './dc:title'); + if (titleElement === null) { + titleElement = feedQueryXPath(this.document, itemElement, + './title'); + } if (titleElement !== null) { title = titleElement.textContent; } @@ -746,22 +757,27 @@ link = parseURL(linkElement.textContent, this.url); } - let pubDateElement = feedQueryXPath(this.document, itemElement, - './pubDate'); - if (pubDateElement !== null) { - date = parseDate(pubDateElement.textContent); + dateElement = feedQueryXPath(this.document, itemElement, './dc:date'); + if (dateElement === null) { + dateElement = feedQueryXPath(this.document, itemElement, + './pubDate'); + } + if (dateElement !== null) { + date = parseDate(dateElement.textContent); } - let encodedElement = feedQueryXPath(this.document, itemElement, + contentElement = feedQueryXPath(this.document, itemElement, './content:encoded'); - if (encodedElement !== null) { - content = encodedElement.textContent.trim(); - } else { - let descriptionElement = feedQueryXPath(this.document, itemElement, + if (contentElement === null) { + contentElement = feedQueryXPath(this.document, itemElement, + './dc:description'); + } + if (contentElement === null) { + contentElement = feedQueryXPath(this.document, itemElement, './description'); - if (descriptionElement !== null) { - content = descriptionElement.textContent.trim(); - } + } + if (contentElement !== null) { + content = contentElement.textContent.trim(); } for (let enclosureElement of @@ -785,14 +801,26 @@ let logo; let entries = []; let documentElement = this.document.documentElement; - let titleElement = feedQueryXPath(this.document, documentElement, - './channel/title'); + let titleElement; + let descriptionElement; + + + titleElement = feedQueryXPath(this.document, documentElement, + './channel/dc:title'); + if (titleElement === null) { + titleElement = feedQueryXPath(this.document, documentElement, + './channel/title'); + } if (titleElement !== null) { title = titleElement.textContent; } - let descriptionElement = feedQueryXPath(this.document, documentElement, - './channel/description'); + descriptionElement = feedQueryXPath(this.document, documentElement, + './channel/dc:description'); + if (descriptionElement === null) { + descriptionElement = feedQueryXPath(this.document, documentElement, + './channel/description'); + } if (descriptionElement !== null) { subtitle = descriptionElement.textContent; }