From 12233603985502aa5c253aaf9641d48c0f4122fe Mon Sep 17 00:00:00 2001 From: Jean-Philippe Monette Date: Sun, 2 Apr 2017 14:24:28 +0100 Subject: [PATCH] Fixing build --- lib/feed.js | 868 ++++++++++++++++++++++-------------------------- lib/feed.js.map | 1 + package.json | 7 +- 3 files changed, 401 insertions(+), 475 deletions(-) mode change 100755 => 100644 lib/feed.js create mode 100644 lib/feed.js.map diff --git a/lib/feed.js b/lib/feed.js old mode 100755 new mode 100644 index a3a99c9..7fb1e14 --- a/lib/feed.js +++ b/lib/feed.js @@ -1,471 +1,397 @@ -var xml = require('xml'); -var url = require('url'); -var generatorName = 'Feed for Node.js'; - -// ============================================================================ -// Feed Main Module -// ============================================================================ -function Feed(options) { - this.id = options.id; - this.title = options.title; - this.description = options.description; - this.link = options.link; - this.image = options.image; - this.copyright = options.copyright; - this.feed = options.feed; - this.hub = options.hub; - this.updated = options.updated; - - this.author = options.author; // Atom only (at channel level) - - this.items = []; - this.categories = []; - this.contributors = []; // Atom only - - this.addItem = function (options) { - options = options || {}; - var item = { - title: options.title, - link: options.link, - description: options.description, - date: options.date, - published: options.published, - image: options.image, - author: options.author, - contributor: options.contributor, // Atom only - guid: options.guid, - id: options.id, - content: options.content, - copyright: options.copyright // Atom only - }; - - this.items.push(item); - return this; - } - - this.addCategory = function (category) { - this.categories.push(category); - return this; - } - - this.addContributor = function (contributor) { - this.contributors.push(contributor); - return this; - } - - this.render = function (format) { - switch(format) { - case 'rss-2.0': - return rss_2_0(this); - break; - - case 'atom-1.0': - return atom_1_0(this); - break; - - default: - return rss_2_0(this); - } - }; - - /** - * DEPRECATED METHODS - */ - this.item = function (options) { - console.warn('DEPRECATED: use addItem() instead of item()'); - return this.addItem(options); - } - - this.category = function (category) { - console.warn('DEPRECATED: use addCategory() instead of category()'); - return this.addCategory(category); - } -}; - -// ============================================================================ -// Atom 1.0 [application/atom+xml] -// -// - Reference: http://www.atomenabled.org/developers/syndication/ -// ============================================================================ - -function atom_1_0(options) { - var items = [], - container = [], - feed = [], - - entries = options.items, - categories = options.categories, - author = options.author, - contributors = options.contributors, - d = new Date(); - - var doctype = '\n'; - - container.push({ feed: feed }); - feed.push({ _attr: { xmlns: 'http://www.w3.org/2005/Atom' }}); - - /************************************************************************** - * "feed" node: REQUIRED elements - *************************************************************************/ - if(options.id == undefined) - throw new Error('feed id is mandatory'); - else - feed.push({ id: options.id }); - - if(options.title == undefined) - throw new Error('feed title is mandatory'); - else - feed.push({ title: options.title }); - - if(options.link == undefined) - throw new Error('feed link is mandatory'); - else - if(!validateURL(options.link)) - throw new Error('invalid feed link'); - - if(Object.prototype.toString.call(options.updated) === '[object Date]') - feed.push({ updated: RFC3339(options.updated) }); - else - feed.push({ updated: RFC3339(d) }); - - /************************************************************************** - * "feed" node: recommended elements - *************************************************************************/ - - if(author) { - var authorDetails = []; - - if(author.name) - authorDetails.push({ name: author.name }); - - if(author.email) - authorDetails.push({ email: author.email }); - - if(author.link) - authorDetails.push({ uri: author.link }); - - feed.push({ author: authorDetails }); - } - - // link (rel="alternate") - if(options.link) - feed.push({ link: { _attr: { rel: 'alternate', href: options.link }}}); - - // link (rel="self") - if(options.feed) - feed.push({ link: { _attr: { rel: 'self', href: options.feed }}}); - - // link (rel="hub") - if(options.hub) - feed.push({ link: { _attr: { rel:'hub', href: options.hub }}}); - - /************************************************************************** - * "feed" node: optional elements - *************************************************************************/ - - if(options.description) - feed.push({ subtitle: options.description }); - - if(options.image) - feed.push({ logo: options.image }); - - if(options.copyright) - feed.push({ rights: options.copyright }); - - feed.push({ generator: generatorName }); - - // Looping through categories (if any set!) - for(var i=0; i {\n feed.push({ category: [{ _attr: { term: category } }] });\n })\n \n this.contributors.forEach(item => {\n const { name, email, link } = item\n let contributor = [];\n \n if(name) {\n contributor.push({ name });\n }\n \n if(email) {\n contributor.push({ email });\n }\n \n if(link) {\n contributor.push({ uri: link });\n }\n\n feed.push({ contributor });\n })\n \n // icon\n\n /**************************************************************************\n * \"entry\" nodes\n *************************************************************************/\n this.items.forEach(item => {\n // \n // entry: required elements\n // \n\n let entry = [\n { title: { _attr: { type: 'html' }, _cdata: item.title }},\n { id: item.id || item.link },\n { link: [{ _attr: { href: item.link } }]},\n { updated: this.ISODateString(item.date) }\n ]\n\n // \n // entry: recommended elements\n // \n if(item.description) {\n entry.push({ summary: { _attr: { type: 'html' }, _cdata: item.description }});\n }\n\n if(item.content) {\n entry.push({ content: { _attr: { type: 'html' }, _cdata: item.content }});\n }\n\n // entry author(s)\n if(Array.isArray(item.author)) {\n item.author.forEach(oneAuthor => {\n const { name, email, link } = oneAuthor\n let author = [];\n \n if(name) {\n author.push({ name });\n }\n \n if(email) {\n author.push({ email });\n }\n \n if(link) {\n author.push({ uri: link });\n }\n\n entry.push({ author });\n })\n }\n\n // content\n\n // link - relative link to article\n\n //\n // entry: optional elements\n // \n\n // category\n\n // contributor\n if(Array.isArray(item.contributor)) {\n item.contributor.forEach(item => {\n const { name, email, link } = item\n let contributor = [];\n \n if(name) {\n contributor.push({ name });\n }\n \n if(email) {\n contributor.push({ email });\n }\n \n if(link) {\n contributor.push({ uri: link });\n }\n \n entry.push({ contributor });\n })\n }\n\n // published\n if(item.published) {\n entry.push({ published: this.ISODateString(item.published) });\n }\n\n // source\n\n // rights\n if(item.copyright) {\n entry.push({ rights: item.copyright });\n }\n\n feed.push({ entry: entry });\n })\n\n return DOCTYPE + xml(root, true); \n }\n\n rss2() {\n const { options } = this\n let isAtom = false\n let isContent = false\n\n let channel = [\n { title: options.title },\n { link: options.link },\n { description: options.description },\n { lastBuildDate: (options.updated ? options.updated.toUTCString() : new Date().toUTCString()) },\n { docs: 'http://blogs.law.harvard.edu/tech/rss'},\n { generator: GENERATOR },\n ]\n\n let rss = [\n { _attr: { version: '2.0' } },\n { channel },\n ]\n\n let root = [{ rss }]\n\n /**\n * Channel Image\n * http://cyber.law.harvard.edu/rss/rss.html#ltimagegtSubelementOfLtchannelgt\n */\n if(options.image) {\n channel.push({\n image: [\n { title: options.title },\n { url: options.image },\n { link: options.link },\n ]\n });\n }\n\n /**\n * Channel Copyright\n * http://cyber.law.harvard.edu/rss/rss.html#optionalChannelElements\n */\n if(options.copyright) {\n channel.push({ copyright: options.copyright });\n }\n \n /**\n * Channel Categories\n * http://cyber.law.harvard.edu/rss/rss.html#comments\n */\n this.categories.forEach(category => {\n channel.push({ category });\n })\n\n /**\n * Feed URL\n * http://validator.w3.org/feed/docs/warning/MissingAtomSelfLink.html\n */\n if(options.feed) {\n isAtom = true\n\n channel.push({\n \"atom:link\": {\n _attr: {\n href: options.feed,\n rel: 'self',\n type: 'application/rss+xml',\n },\n },\n })\n }\n \n /**\n * Hub for PubSubHubbub\n * https://code.google.com/p/pubsubhubbub/\n */\n if(options.hub) {\n isAtom = true;\n channel.push({\n \"atom:link\": {\n _attr: {\n href: options.hub,\n rel: 'hub',\n },\n },\n })\n }\n\n /**\n * Channel Categories\n * http://cyber.law.harvard.edu/rss/rss.html#hrelementsOfLtitemgt\n */\n this.items.forEach(entry => {\n let item = [];\n\n if(entry.title) {\n item.push({ title: { _cdata: entry.title }});\n }\n\n if(entry.link) {\n item.push({ link: entry.link });\n }\n\n if(entry.guid) {\n item.push({ guid: entry.guid });\n } else if (entry.link) {\n item.push({ guid: entry.link });\n }\n\n if(entry.date) {\n item.push({ pubDate: entry.date.toUTCString() });\n }\n\n if(entry.description) {\n item.push({ description: { _cdata: entry.description }});\n }\n\n if(entry.content) {\n isContent = true;\n item.push({ 'content:encoded': { _cdata: entry.content }});\n }\n /**\n * Item Author\n * http://cyber.law.harvard.edu/rss/rss.html#ltauthorgtSubelementOfLtitemgt\n */\n if(Array.isArray(entry.author)) {\n entry.author.some(author => {\n if (author.email && author.name) {\n item.push({ author: author.email + ' (' + author.name + ')' })\n return true\n } else {\n return false\n }\n })\n }\n\n if(item.image) {\n item.push({ enclosure: [{ _attr: { url: entry.image } }] });\n }\n\n channel.push({ item });\n })\n\n if(isContent) {\n rss[0]._attr['xmlns:content'] = 'http://purl.org/rss/1.0/modules/content/';\n }\n\n if(isAtom) {\n rss[0]._attr['xmlns:atom'] = 'http://www.w3.org/2005/Atom';\n }\n\n return DOCTYPE + xml(root, true);\n }\n\n ISODateString(d) {\n function pad(n) {\n return n<10 ? '0'+n : n\n }\n\n return d.getUTCFullYear() + '-'\n + pad(d.getUTCMonth() + 1) + '-'\n + pad(d.getUTCDate()) + 'T'\n + pad(d.getUTCHours()) + ':'\n + pad(d.getUTCMinutes()) + ':'\n + pad(d.getUTCSeconds()) + 'Z'\n }\n\n}\n\nmodule.exports = Feed"]} \ No newline at end of file diff --git a/package.json b/package.json index f1eb024..1586d2d 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "feed", - "version": "1.0.0", + "version": "1.0.1", "description": "Feed is a RSS and Atom feed generator for Node.js, making content syndication simple and intuitive!", "homepage": "http://projets.jpmonette.net/en/feed", "author": "Jean-Philippe Monette ", @@ -13,9 +13,8 @@ "license": "MIT", "main": "lib/feed.js", "scripts": { - "build": "babel -d lib/ src/ --ignore **/*.spec.js -s", - "prebuild": "rm -rf lib/ && mkdir lib", - "prepublish": "npm run prebuild", + "build": "rm -rf lib/ && mkdir lib && babel -d lib/ src/ --ignore **/*.spec.js -s", + "prepublish": "npm run build", "test": "export NODE_ENV=test && jest", "test-travis": "export NODE_ENV=test && jest" },