From 87ca622784fcda713924f9e0ad32a7a2b0128b23 Mon Sep 17 00:00:00 2001 From: Zach Foster Date: Thu, 14 Sep 2017 09:46:32 -0700 Subject: [PATCH] fix(images): Fixes image enclosures for items --- lib/feed.js | 2 +- lib/feed.js.map | 2 +- src/feed.js | 2 +- src/feed.spec.js | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/feed.js b/lib/feed.js index e1b3833..86b781e 100644 --- a/lib/feed.js +++ b/lib/feed.js @@ -368,7 +368,7 @@ var Feed = function () { }); } - if (item.image) { + if (entry.image) { item.push({ enclosure: [{ _attr: { url: entry.image } }] }); } diff --git a/lib/feed.js.map b/lib/feed.js.map index bcd5f12..064ddb4 100644 --- a/lib/feed.js.map +++ b/lib/feed.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/feed.js"],"names":["GENERATOR","DOCTYPE","Feed","options","items","categories","contributors","item","push","category","contributor","format","console","warn","atom1","rss2","feed","_attr","xmlns","id","title","updated","ISODateString","Date","generator","root","author","name","email","link","uri","rel","href","atomLink","feedLinks","atom","hub","description","subtitle","image","logo","favicon","icon","copyright","rights","forEach","term","entry","type","_cdata","date","summary","content","Array","isArray","oneAuthor","published","isAtom","isContent","channel","lastBuildDate","toUTCString","docs","rss","version","url","guid","pubDate","some","enclosure","home_page_url","json","feed_url","map","feedItem","html_content","date_modified","date_published","JSON","stringify","d","pad","n","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","module","exports"],"mappings":";;;;AAAA;;;;;;;;AAEA,IAAMA,YAAY,kBAAlB;AACA,IAAMC,UAAU,0CAAhB;;IAEMC,I;AAEJ,gBAAYC,OAAZ,EAAqB;AAAA;;AACnB,SAAKA,OAAL,GAAeA,OAAf;AACA,SAAKC,KAAL,GAAa,EAAb;AACA,SAAKC,UAAL,GAAkB,EAAlB;AACA,SAAKC,YAAL,GAAoB,EAApB;AACD;;;;4BAEOC,I,EAAM;AACZ,WAAKH,KAAL,CAAW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AIA,CAAX,GAAeA,CAAtB;AACD;;AAED,aAAOF,EAAEG,cAAF,KAAqB,GAArB,GACHF,IAAID,EAAEI,WAAF,KAAkB,CAAtB,CADG,GACwB,GADxB,GAEHH,IAAID,EAAEK,UAAF,EAAJ,CAFG,GAEmB,GAFnB,GAGHJ,IAAID,EAAEM,WAAF,EAAJ,CAHG,GAGoB,GAHpB,GAIHL,IAAID,EAAEO,aAAF,EAAJ,CAJG,GAIsB,GAJtB,GAKHN,IAAID,EAAEQ,aAAF,EAAJ,CALG,GAKsB,GAL7B;AAMD;;;;;;AAIHC,OAAOC,OAAP,GAAiBxF,IAAjB","file":"feed.js","sourcesContent":["import xml from 'xml'\n\nconst GENERATOR = 'Feed for Node.js'\nconst DOCTYPE = '\\n'\n\nclass Feed {\n\n constructor(options) {\n this.options = options\n this.items = []\n this.categories = []\n this.contributors = []\n }\n\n addItem(item) {\n this.items.push(item)\n }\n\n addCategory(category) {\n this.categories.push(category)\n }\n\n addContributor(contributor) {\n this.contributors.push(contributor)\n }\n\n render(format) {\n console.warn('DEPRECATED: use atom1() or rss2() instead of render()');\n if (format === 'atom-1.0') {\n return this.atom1();\n } else {\n return this.rss2();\n }\n }\n\n atom1() {\n const { options } = this\n\n let feed = [\n { _attr: { xmlns: 'http://www.w3.org/2005/Atom' } },\n { id: options.id },\n { title: options.title },\n { updated: (options.updated ? this.ISODateString(options.updated) : this.ISODateString(new Date())) },\n { generator: options.generator || GENERATOR },\n ]\n\n let root = [{ feed }]\n\n if (options.author) {\n const { name, email, link } = options.author\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 feed.push({ author })\n }\n\n // link (rel=\"alternate\")\n if(options.link) {\n feed.push({ link: { _attr: { rel: 'alternate', href: options.link }}});\n }\n\n // link (rel=\"self\")\n const atomLink = options.feed || (options.feedLinks && options.feedLinks.atom);\n if(atomLink) {\n feed.push({ \"link\": { _attr: { rel: 'self', href: atomLink }}});\n }\n\n // link (rel=\"hub\")\n if(options.hub) {\n feed.push({ link: { _attr: { rel:'hub', href: options.hub }}});\n }\n\n /**************************************************************************\n * \"feed\" node: optional elements\n *************************************************************************/\n\n if(options.description) {\n feed.push({ subtitle: options.description });\n }\n\n if(options.image) {\n feed.push({ logo: options.image });\n }\n\n if(options.favicon) {\n feed.push({ icon: options.favicon });\n }\n\n if(options.copyright) {\n feed.push({ rights: options.copyright });\n }\n\n this.categories.forEach(category => {\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: options.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 const atomLink = options.feed || (options.feedLinks && options.feedLinks.atom);\n if(atomLink) {\n isAtom = true\n\n channel.push({\n \"atom:link\": {\n _attr: {\n href: atomLink,\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 json1() {\n const { options, items } = this\n let feed = {\n version: 'https://jsonfeed.org/version/1',\n title: options.title,\n };\n\n if (options.link) {\n feed.home_page_url = options.link;\n }\n\n if (options.feedLinks && options.feedLinks.json) {\n feed.feed_url = options.feedLinks.json;\n }\n\n if (options.description) {\n feed.description = options.description;\n }\n\n\n if (options.image) {\n feed.icon = options.image;\n }\n\n if (options.author) {\n feed.author = {};\n if (options.author.name) {\n feed.author.name = options.author.name;\n }\n if (options.author.link) {\n feed.author.url = options.author.link;\n }\n }\n feed.items = items.map(item => {\n let feedItem = {\n id: item.id,\n // json_feed distinguishes between html and text content\n // but since we only take a single type, we'll assume HTML\n html_content: item.content,\n }\n if (item.link) {\n feedItem.url = item.link;\n }\n if(item.title) {\n feedItem.title = item.title;\n }\n if (item.description) {\n feedItem.summary = item.description;\n }\n\n if (item.image) {\n feedItem.image = item.image\n }\n\n if (item.date) {\n feedItem.date_modified = this.ISODateString(item.date);\n }\n if (item.published) {\n feedItem.date_published = this.ISODateString(item.published);\n }\n\n if (item.author) {\n let author = item.author;\n if (author instanceof Array) {\n // json feed only supports 1 author per post\n author = author[0];\n }\n feedItem.author = {};\n if (author.name) {\n feedItem.author.name = author.name;\n }\n if (author.link) {\n feedItem.author.url = author.link;\n }\n }\n return feedItem;\n });\n\n return JSON.stringify(feed, null, 4);\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\n"]} \ No newline at end of file +{"version":3,"sources":["../src/feed.js"],"names":["GENERATOR","DOCTYPE","Feed","options","items","categories","contributors","item","push","category","contributor","format","console","warn","atom1","rss2","feed","_attr","xmlns","id","title","updated","ISODateString","Date","generator","root","author","name","email","link","uri","rel","href","atomLink","feedLinks","atom","hub","description","subtitle","image","logo","favicon","icon","copyright","rights","forEach","term","entry","type","_cdata","date","summary","content","Array","isArray","oneAuthor","published","isAtom","isContent","channel","lastBuildDate","toUTCString","docs","rss","version","url","guid","pubDate","some","enclosure","home_page_url","json","feed_url","map","feedItem","html_content","date_modified","date_published","JSON","stringify","d","pad","n","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","module","exports"],"mappings":";;;;AAAA;;;;;;;;AAEA,IAAMA,YAAY,kBAAlB;AACA,IAAMC,UAAU,0CAAhB;;IAEMC,I;AAEJ,gBAAYC,OAAZ,EAAqB;AAAA;;AACnB,SAAKA,OAAL,GAAeA,OAAf;AACA,SAAKC,KAAL,GAAa,EAAb;AACA,SAAKC,UAAL,GAAkB,EAAlB;AACA,SAAKC,YAAL,GAAoB,EAApB;AACD;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AAb,EAAgB;AACd,eAAOA,IAAE,EAAF,GAAO,MAAIA,CAAX,GAAeA,CAAtB;AACD;;AAED,aAAOF,EAAEG,cAAF,KAAqB,GAArB,GACHF,IAAID,EAAEI,WAAF,KAAkB,CAAtB,CADG,GACwB,GADxB,GAEHH,IAAID,EAAEK,UAAF,EAAJ,CAFG,GAEmB,GAFnB,GAGHJ,IAAID,EAAEM,WAAF,EAAJ,CAHG,GAGoB,GAHpB,GAIHL,IAAID,EAAEO,aAAF,EAAJ,CAJG,GAIsB,GAJtB,GAKHN,IAAID,EAAEQ,aAAF,EAAJ,CALG,GAKsB,GAL7B;AAMD;;;;;;AAIHC,OAAOC,OAAP,GAAiBxF,IAAjB","file":"feed.js","sourcesContent":["import xml from 'xml'\n\nconst GENERATOR = 'Feed for Node.js'\nconst DOCTYPE = '\\n'\n\nclass Feed {\n\n constructor(options) {\n this.options = options\n this.items = []\n this.categories = []\n this.contributors = []\n }\n\n addItem(item) {\n this.items.push(item)\n }\n\n addCategory(category) {\n this.categories.push(category)\n }\n\n addContributor(contributor) {\n this.contributors.push(contributor)\n }\n\n render(format) {\n console.warn('DEPRECATED: use atom1() or rss2() instead of render()');\n if (format === 'atom-1.0') {\n return this.atom1();\n } else {\n return this.rss2();\n }\n }\n\n atom1() {\n const { options } = this\n\n let feed = [\n { _attr: { xmlns: 'http://www.w3.org/2005/Atom' } },\n { id: options.id },\n { title: options.title },\n { updated: (options.updated ? this.ISODateString(options.updated) : this.ISODateString(new Date())) },\n { generator: options.generator || GENERATOR },\n ]\n\n let root = [{ feed }]\n\n if (options.author) {\n const { name, email, link } = options.author\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 feed.push({ author })\n }\n\n // link (rel=\"alternate\")\n if(options.link) {\n feed.push({ link: { _attr: { rel: 'alternate', href: options.link }}});\n }\n\n // link (rel=\"self\")\n const atomLink = options.feed || (options.feedLinks && options.feedLinks.atom);\n if(atomLink) {\n feed.push({ \"link\": { _attr: { rel: 'self', href: atomLink }}});\n }\n\n // link (rel=\"hub\")\n if(options.hub) {\n feed.push({ link: { _attr: { rel:'hub', href: options.hub }}});\n }\n\n /**************************************************************************\n * \"feed\" node: optional elements\n *************************************************************************/\n\n if(options.description) {\n feed.push({ subtitle: options.description });\n }\n\n if(options.image) {\n feed.push({ logo: options.image });\n }\n\n if(options.favicon) {\n feed.push({ icon: options.favicon });\n }\n\n if(options.copyright) {\n feed.push({ rights: options.copyright });\n }\n\n this.categories.forEach(category => {\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: options.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 const atomLink = options.feed || (options.feedLinks && options.feedLinks.atom);\n if(atomLink) {\n isAtom = true\n\n channel.push({\n \"atom:link\": {\n _attr: {\n href: atomLink,\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(entry.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 json1() {\n const { options, items } = this\n let feed = {\n version: 'https://jsonfeed.org/version/1',\n title: options.title,\n };\n\n if (options.link) {\n feed.home_page_url = options.link;\n }\n\n if (options.feedLinks && options.feedLinks.json) {\n feed.feed_url = options.feedLinks.json;\n }\n\n if (options.description) {\n feed.description = options.description;\n }\n\n\n if (options.image) {\n feed.icon = options.image;\n }\n\n if (options.author) {\n feed.author = {};\n if (options.author.name) {\n feed.author.name = options.author.name;\n }\n if (options.author.link) {\n feed.author.url = options.author.link;\n }\n }\n feed.items = items.map(item => {\n let feedItem = {\n id: item.id,\n // json_feed distinguishes between html and text content\n // but since we only take a single type, we'll assume HTML\n html_content: item.content,\n }\n if (item.link) {\n feedItem.url = item.link;\n }\n if(item.title) {\n feedItem.title = item.title;\n }\n if (item.description) {\n feedItem.summary = item.description;\n }\n\n if (item.image) {\n feedItem.image = item.image\n }\n\n if (item.date) {\n feedItem.date_modified = this.ISODateString(item.date);\n }\n if (item.published) {\n feedItem.date_published = this.ISODateString(item.published);\n }\n\n if (item.author) {\n let author = item.author;\n if (author instanceof Array) {\n // json feed only supports 1 author per post\n author = author[0];\n }\n feedItem.author = {};\n if (author.name) {\n feedItem.author.name = author.name;\n }\n if (author.link) {\n feedItem.author.url = author.link;\n }\n }\n return feedItem;\n });\n\n return JSON.stringify(feed, null, 4);\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\n"]} \ No newline at end of file diff --git a/src/feed.js b/src/feed.js index a625a00..e1710b9 100644 --- a/src/feed.js +++ b/src/feed.js @@ -358,7 +358,7 @@ class Feed { }) } - if(item.image) { + if(entry.image) { item.push({ enclosure: [{ _attr: { url: entry.image } }] }); } diff --git a/src/feed.spec.js b/src/feed.spec.js index af31162..ed7af2f 100644 --- a/src/feed.spec.js +++ b/src/feed.spec.js @@ -80,6 +80,8 @@ test('it should generate an RSS 2.0 feed', () => { Sat, 13 Jul 2013 23:00:00 GMT janedoe@example.com (Jane Doe) + + `;