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 Jul 05 13:29:29 2019 +0200 (11 months ago)
parents b68880838990
children f4e8aa4d50da
files js/feed-parser.js
line diff
     1.1 --- a/js/feed-parser.js	Wed Jul 03 16:57:17 2019 +0200
     1.2 +++ b/js/feed-parser.js	Fri Jul 05 13:29:29 2019 +0200
     1.3 @@ -14,6 +14,7 @@
     1.4      RSS09: 'http://my.netscape.com/rdf/simple/0.9/',
     1.5      RSS10: 'http://purl.org/rss/1.0/',
     1.6      CONTENT: 'http://purl.org/rss/1.0/modules/content/',
     1.7 +    DC: 'http://purl.org/dc/elements/1.1/',
     1.8      XHTML: 'http://www.w3.org/1999/xhtml',
     1.9      PARSERERROR: 'http://www.mozilla.org/newlayout/xml/parsererror.xml'
    1.10  }
    1.11 @@ -78,6 +79,8 @@
    1.12              return XMLNS.RSS10;
    1.13          case 'content':
    1.14              return XMLNS.CONTENT;
    1.15 +        case 'dc':
    1.16 +            return XMLNS.DC;
    1.17      }
    1.18      return null;
    1.19  }
    1.20 @@ -735,8 +738,16 @@
    1.21          let date;
    1.22          let content;
    1.23          let files = [];
    1.24 -        let titleElement = feedQueryXPath(this.document, itemElement,
    1.25 -                './title');
    1.26 +        let titleElement;
    1.27 +        let dateElement;
    1.28 +        let contentElement;
    1.29 +
    1.30 +        titleElement = feedQueryXPath(this.document, itemElement,
    1.31 +                './dc:title');
    1.32 +        if (titleElement === null) {
    1.33 +            titleElement = feedQueryXPath(this.document, itemElement,
    1.34 +                    './title');
    1.35 +        }
    1.36          if (titleElement !== null) {
    1.37              title = titleElement.textContent;
    1.38          }
    1.39 @@ -746,22 +757,27 @@
    1.40              link = parseURL(linkElement.textContent, this.url);
    1.41          }
    1.42  
    1.43 -        let pubDateElement = feedQueryXPath(this.document, itemElement,
    1.44 -                './pubDate');
    1.45 -        if (pubDateElement !== null) {
    1.46 -            date = parseDate(pubDateElement.textContent);
    1.47 +        dateElement = feedQueryXPath(this.document, itemElement, './dc:date');
    1.48 +        if (dateElement === null) {
    1.49 +            dateElement = feedQueryXPath(this.document, itemElement,
    1.50 +                    './pubDate');
    1.51 +        }
    1.52 +        if (dateElement !== null) {
    1.53 +            date = parseDate(dateElement.textContent);
    1.54          }
    1.55  
    1.56 -        let encodedElement = feedQueryXPath(this.document, itemElement,
    1.57 +        contentElement = feedQueryXPath(this.document, itemElement,
    1.58                  './content:encoded');
    1.59 -        if (encodedElement !== null) {
    1.60 -            content = encodedElement.textContent.trim();
    1.61 -        } else {
    1.62 -            let descriptionElement = feedQueryXPath(this.document, itemElement,
    1.63 +        if (contentElement === null) {
    1.64 +            contentElement = feedQueryXPath(this.document, itemElement,
    1.65 +                    './dc:description');
    1.66 +        }
    1.67 +        if (contentElement === null) {
    1.68 +            contentElement = feedQueryXPath(this.document, itemElement,
    1.69                      './description');
    1.70 -            if (descriptionElement !== null) {
    1.71 -                content = descriptionElement.textContent.trim();
    1.72 -            }
    1.73 +        }
    1.74 +        if (contentElement !== null) {
    1.75 +            content = contentElement.textContent.trim();
    1.76          }
    1.77  
    1.78          for (let enclosureElement of
    1.79 @@ -785,14 +801,26 @@
    1.80          let logo;
    1.81          let entries = [];
    1.82          let documentElement = this.document.documentElement;
    1.83 -        let titleElement = feedQueryXPath(this.document, documentElement,
    1.84 -                './channel/title');
    1.85 +        let titleElement;
    1.86 +        let descriptionElement;
    1.87 +
    1.88 +
    1.89 +        titleElement = feedQueryXPath(this.document, documentElement,
    1.90 +                './channel/dc:title');
    1.91 +        if (titleElement === null) {
    1.92 +            titleElement = feedQueryXPath(this.document, documentElement,
    1.93 +                    './channel/title');
    1.94 +        }
    1.95          if (titleElement !== null) {
    1.96              title = titleElement.textContent;
    1.97          }
    1.98  
    1.99 -        let descriptionElement = feedQueryXPath(this.document, documentElement,
   1.100 -                './channel/description');
   1.101 +        descriptionElement = feedQueryXPath(this.document, documentElement,
   1.102 +                './channel/dc:description');
   1.103 +        if (descriptionElement === null) {
   1.104 +            descriptionElement = feedQueryXPath(this.document, documentElement,
   1.105 +                    './channel/description');
   1.106 +        }
   1.107          if (descriptionElement !== null) {
   1.108              subtitle = descriptionElement.textContent;
   1.109          }