From 67d32147f29b85b002ca1478b8bb4e1e50633058 Mon Sep 17 00:00:00 2001 From: Ryo Yamamoto Date: Sat, 20 May 2017 11:02:43 +0900 Subject: [PATCH 1/5] fix handling of 'image' parameter --- src/feed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/feed.js b/src/feed.js index 4b685dc..550d9f8 100644 --- a/src/feed.js +++ b/src/feed.js @@ -352,7 +352,7 @@ class Feed { }) } - if(item.image) { + if(entry.image) { item.push({ enclosure: [{ _attr: { url: entry.image } }] }); } From 00d3882fe7a584b2a2a6b5c6cf9521b88af17e7e Mon Sep 17 00:00:00 2001 From: Ryo Yamamoto Date: Sat, 20 May 2017 11:13:30 +0900 Subject: [PATCH 2/5] fix handling of 'image' parameter --- lib/feed.js | 2 +- lib/feed.js.map | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/feed.js b/lib/feed.js index e78f687..6fcb98e 100644 --- a/lib/feed.js +++ b/lib/feed.js @@ -362,7 +362,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 087d1be..abc3835 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","hub","description","subtitle","image","logo","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","d","pad","n","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","module","exports"],"mappings":";;;;AAAA;;;;;;;;AAEA,IAAMA,YAAY,kBAAlB;AACA,IAAMC,UAAU,0C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AACTM,YAAI,CAAJ,EAAOzC,KAAP,CAAa,YAAb,IAA6B,6BAA7B;AACD;;AAED,aAAOhB,UAAU,mBAAIwB,IAAJ,EAAU,IAAV,CAAjB;AACD;;;kCAEawC,C,EAAG;AACf,eAASC,GAAT,CAAaC,CAAb,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,GAAiBzE,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: 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 if(options.feed) {\n feed.push({ \"link\": { _attr: { rel: 'self', href: options.feed }}});\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.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: 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 +{"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","hub","description","subtitle","image","logo","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","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,CAAWI,IAAX,CAAgBD,IAAhB;AACD;;;gCAEWE,Q,EAAU;AACpB,WAAKJ,UAAL,CAAgBG,IAAhB,CAAqBC,QAArB;AACD;;;mCAEcC,W,EAAa;AAC1B,WAAKJ,YAAL,CAAkBE,IAAlB,CAAuBE,WAAvB;AACD;;;2BAEMC,M,EAAQ;AACbC,cAAQC,IAAR,CAAa,uDAAb;AACA,UAAIF,WAAW,UAAf,EAA2B;AACzB,eAAO,KAAKG,KAAL,EAAP;AACD,OAFD,MAEO;AACL,eAAO,KAAKC,IAAL,EAAP;AACD;AACF;;;4BAEO;AAAA;;AAAA,UACEZ,OADF,GACc,IADd,CACEA,OADF;;;AAGN,UAAIa,OAAO,CACT,EAAEC,OAAO,EAAEC,OAAO,6BAAT,EAAT,EADS,EAET,EAAEC,IAAIhB,QAAQgB,EAAd,EAFS,EAGT,EAAEC,OAAOjB,QAAQiB,KAAjB,EAHS,EAIT,EAAEC,SAAUlB,QAAQkB,OAAR,GAAkB,KAAKC,aAAL,CAAmBnB,QAAQkB,OAA3B,CAAlB,GAAwD,KAAKC,aAAL,CAAmB,IAAIC,IAAJ,EAAnB,CAApE,EAJS,EAKT,EAAEC,WAAWxB,SAAb,EALS,CAAX;;AAQA,UAAIyB,OAA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B,MAAMN,KAAb,EAAT,EAAD,CAAb,EAAV;AACD;;AAEDkB,gBAAQ9C,IAAR,CAAa,EAAED,UAAF,EAAb;AACD,OAjDD;;AAmDA,UAAG8C,SAAH,EAAc;AACZK,YAAI,CAAJ,EAAOzC,KAAP,CAAa,eAAb,IAAgC,0CAAhC;AACD;;AAED,UAAGmC,MAAH,EAAW;AACTM,YAAI,CAAJ,EAAOzC,KAAP,CAAa,YAAb,IAA6B,6BAA7B;AACD;;AAED,aAAOhB,UAAU,mBAAIwB,IAAJ,EAAU,IAAV,CAAjB;AACD;;;kCAEawC,C,EAAG;AACf,eAASC,GAAT,CAAaC,CAAb,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,GAAiBzE,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: 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 if(options.feed) {\n feed.push({ \"link\": { _attr: { rel: 'self', href: options.feed }}});\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.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: 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(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 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 From f8795c753d10e835a6c185fa3046ef9e4b27bd74 Mon Sep 17 00:00:00 2001 From: Ryo Yamamoto Date: Sat, 20 May 2017 11:23:16 +0900 Subject: [PATCH 3/5] fix handling of 'image' parameter --- lib/feed.js | 7 ++++++- lib/feed.js.map | 2 +- src/feed.js | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/feed.js b/lib/feed.js index 6fcb98e..27b5b25 100644 --- a/lib/feed.js +++ b/lib/feed.js @@ -6,6 +6,10 @@ var _xml = require('xml'); var _xml2 = _interopRequireDefault(_xml); +var _path = require('path'); + +var _path2 = _interopRequireDefault(_path); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -363,7 +367,8 @@ var Feed = function () { } if (entry.image) { - item.push({ enclosure: [{ _attr: { url: entry.image } }] }); + var imgExt = _path2.default.extname(entry.image).substr(1); + item.push({ enclosure: [{ _attr: { url: entry.image, type: 'image/' + imgExt } }] }); } channel.push({ item: item }); diff --git a/lib/feed.js.map b/lib/feed.js.map index abc3835..ce90ac9 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","hub","description","subtitle","image","logo","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","d","pad","n","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","module","exports"],"mappings":";;;;AAAA;;;;;;;;AAEA,IAAMA,YAAY,kBAAlB;AACA,IAAMC,UAAU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W;AACTM,YAAI,CAAJ,EAAOzC,KAAP,CAAa,YAAb,IAA6B,6BAA7B;AACD;;AAED,aAAOhB,UAAU,mBAAIwB,IAAJ,EAAU,IAAV,CAAjB;AACD;;;kCAEawC,C,EAAG;AACf,eAASC,GAAT,CAAaC,CAAb,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,GAAiBzE,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: 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 if(options.feed) {\n feed.push({ \"link\": { _attr: { rel: 'self', href: options.feed }}});\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.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: 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(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 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 +{"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","hub","description","subtitle","image","logo","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","imgExt","extname","substr","enclosure","d","pad","n","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","module","exports"],"mappings":";;;;AAAA;;;;AACA;;;;;;;;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,CAAWI,IAAX,CAAgBD,IAAhB;AACD;;;gCAEWE,Q,EAAU;AACpB,WAAKJ,UAAL,CAAgBG,IAAhB,CAAqBC,QAArB;AACD;;;mCAEcC,W,EAAa;AAC1B,WAAKJ,YAAL,CAAkBE,IAAlB,CAAuBE,WAAvB;AACD;;;2BAEMC,M,EAAQ;AACbC,cAAQC,IAAR,CAAa,uDAAb;AACA,UAAIF,WAAW,UAAf,EAA2B;AACzB,eAAO,KAAKG,KAAL,EAAP;AACD,OAFD,MAEO;AACL,eAAO,KAAKC,IAAL,EAAP;AACD;AACF;;;4BAEO;AAAA;;AAAA,UACEZ,OADF,GACc,IADd,CACEA,OADF;;;AAGN,UAAIa,OAAO,CACT,EAAEC,OAAO,EAAEC,OAAO,6BAAT,EAAT,EADS,EAET,EAAEC,IAAIhB,QAAQgB,EAAd,EAFS,EAGT,EAAEC,OAAOjB,QAAQiB,KAAjB,EAHS,EAIT,EAAEC,SAAUlB,QAAQkB,OAAR,GAAkB,KAAKC,aAAL,CAAmBnB,QAAQkB,OAA3B,CAAlB,GAAwD,KAAKC,aAAL,CAAmB,IAAIC,IAAJ,EAAnB,CAApE,EAJS,EAKT,EAAEC,WAAWxB,SAAb,EALS,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AnB,EAA0B8B,MAA1B,CAAiC,CAAjC,CAAb;AACA3D,eAAKC,IAAL,CAAU,EAAE2D,WAAW,CAAC,EAAElD,OAAO,EAAE2C,KAAKlB,MAAMN,KAAb,EAAoBO,MAAM,WAASqB,MAAnC,EAAT,EAAD,CAAb,EAAV;AACH;;AAEDV,gBAAQ9C,IAAR,CAAa,EAAED,UAAF,EAAb;AACD,OAlDD;;AAoDA,UAAG8C,SAAH,EAAc;AACZK,YAAI,CAAJ,EAAOzC,KAAP,CAAa,eAAb,IAAgC,0CAAhC;AACD;;AAED,UAAGmC,MAAH,EAAW;AACTM,YAAI,CAAJ,EAAOzC,KAAP,CAAa,YAAb,IAA6B,6BAA7B;AACD;;AAED,aAAOhB,UAAU,mBAAIwB,IAAJ,EAAU,IAAV,CAAjB;AACD;;;kCAEa2C,C,EAAG;AACf,eAASC,GAAT,CAAaC,CAAb,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,GAAiB5E,IAAjB","file":"feed.js","sourcesContent":["import xml from 'xml'\nimport path from 'path'\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: 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 if(options.feed) {\n feed.push({ \"link\": { _attr: { rel: 'self', href: options.feed }}});\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.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: 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(entry.image) {\n var imgExt = path.extname(entry.image).substr(1);\n item.push({ enclosure: [{ _attr: { url: entry.image, type: 'image/'+imgExt } }] });\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/src/feed.js b/src/feed.js index 550d9f8..67b7bb4 100644 --- a/src/feed.js +++ b/src/feed.js @@ -1,4 +1,5 @@ import xml from 'xml' +import path from 'path' const GENERATOR = 'Feed for Node.js' const DOCTYPE = '\n' @@ -353,7 +354,8 @@ class Feed { } if(entry.image) { - item.push({ enclosure: [{ _attr: { url: entry.image } }] }); + var imgExt = path.extname(entry.image).substr(1); + item.push({ enclosure: [{ _attr: { url: entry.image, type: 'image/'+imgExt } }] }); } channel.push({ item }); From 27f4eaa89eb7034bb7857f0e0d163e2002185203 Mon Sep 17 00:00:00 2001 From: Ryo Yamamoto Date: Sun, 21 May 2017 05:27:03 +0900 Subject: [PATCH 4/5] predict mime-type from url string with library "mime-type" --- lib/feed.js | 12 +++-- lib/feed.js.map | 2 +- package.json | 119 ++++++++++++++++++++++++----------------------- src/feed.js | 10 ++-- src/feed.spec.js | 2 + 5 files changed, 78 insertions(+), 67 deletions(-) mode change 100755 => 100644 package.json diff --git a/lib/feed.js b/lib/feed.js index 27b5b25..cf02220 100644 --- a/lib/feed.js +++ b/lib/feed.js @@ -6,9 +6,9 @@ var _xml = require('xml'); var _xml2 = _interopRequireDefault(_xml); -var _path = require('path'); +var _mimeTypes = require('mime-types'); -var _path2 = _interopRequireDefault(_path); +var _mimeTypes2 = _interopRequireDefault(_mimeTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -367,8 +367,12 @@ var Feed = function () { } if (entry.image) { - var imgExt = _path2.default.extname(entry.image).substr(1); - item.push({ enclosure: [{ _attr: { url: entry.image, type: 'image/' + imgExt } }] }); + var attr = { url: entry.image }; + var contentType = _mimeTypes2.default.lookup(entry.image); + if (contentType && contentType.indexOf('image/') == 0) { + attr.type = contentType; + } + item.push({ enclosure: [{ _attr: attr }] }); } channel.push({ item: item }); diff --git a/lib/feed.js.map b/lib/feed.js.map index ce90ac9..4eccc28 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","hub","description","subtitle","image","logo","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","imgExt","extname","substr","enclosure","d","pad","n","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","module","exports"],"mappings":";;;;AAAA;;;;AACA;;;;;;;;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,CAAWI,IAAX,CAAgBD,IAAhB;AACD;;;gCAEWE,Q,EAAU;AACpB,WAAKJ,UAAL,CAAgBG,IAAhB,CAAqBC,QAArB;AACD;;;mCAEcC,W,EAAa;AAC1B,WAAKJ,YAAL,CAAkBE,IAAlB,CAAuBE,WAAvB;AACD;;;2BAEMC,M,EAAQ;AACbC,cAAQC,IAAR,CAAa,uDAAb;AACA,UAAIF,WAAW,UAAf,EAA2B;AACzB,eAAO,KAAKG,KAAL,EAAP;AACD,OAFD,MAEO;AACL,eAAO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HG,GAGoB,GAHpB,GAIHL,IAAID,EAAEO,aAAF,EAAJ,CAJG,GAIsB,GAJtB,GAKHN,IAAID,EAAEQ,aAAF,EAAJ,CALG,GAKsB,GAL7B;AAMD;;;;;;AAIHC,OAAOC,OAAP,GAAiB5E,IAAjB","file":"feed.js","sourcesContent":["import xml from 'xml'\nimport path from 'path'\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: 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 if(options.feed) {\n feed.push({ \"link\": { _attr: { rel: 'self', href: options.feed }}});\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.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: 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(entry.image) {\n var imgExt = path.extname(entry.image).substr(1);\n item.push({ enclosure: [{ _attr: { url: entry.image, type: 'image/'+imgExt } }] });\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 +{"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","hub","description","subtitle","image","logo","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","attr","contentType","lookup","indexOf","enclosure","d","pad","n","getUTCFullYear","getUTCMonth","getUTCDate","getUTCHours","getUTCMinutes","getUTCSeconds","module","exports"],"mappings":";;;;AAAA;;;;AACA;;;;;;;;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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,CAAJ,EAAOzC,KAAP,CAAa,eAAb,IAAgC,0CAAhC;AACD;;AAED,UAAGmC,MAAH,EAAW;AACTM,YAAI,CAAJ,EAAOzC,KAAP,CAAa,YAAb,IAA6B,6BAA7B;AACD;;AAED,aAAOhB,UAAU,mBAAIwB,IAAJ,EAAU,IAAV,CAAjB;AACD;;;kCAEa4C,C,EAAG;AACf,eAASC,GAAT,CAAaC,CAAb,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,GAAiB7E,IAAjB","file":"feed.js","sourcesContent":["import xml from 'xml'\nimport mime from 'mime-types'\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: 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 if(options.feed) {\n feed.push({ \"link\": { _attr: { rel: 'self', href: options.feed }}});\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.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: 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(entry.image) {\n let attr = { url: entry.image };\n let contentType = mime.lookup(entry.image);\n if(contentType && contentType.indexOf('image/')==0) {\n attr.type = contentType;\n }\n item.push({ enclosure: [{ _attr: attr }] });\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 old mode 100755 new mode 100644 index cb15fc8..179cd90 --- a/package.json +++ b/package.json @@ -1,59 +1,60 @@ -{ - "name": "feed", - "version": "1.0.2", - "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 ", - "contributors": [ - { - "name": "Pierre Galvez", - "email": "contact@pierre-galvez.fr" - } - ], - "license": "MIT", - "main": "lib/feed.js", - "scripts": { - "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" - }, - "jest": { - "verbose": true, - "collectCoverage": true, - "collectCoverageFrom": [ - "**/src/*.{js}" - ], - "testMatch": [ - "**/*.spec.js" - ] - }, - "keywords": [ - "rss", - "atom", - "feed", - "syndication", - "xml", - "wrapper", - "blog" - ], - "dependencies": { - "xml": ">= 0.0.5" - }, - "devDependencies": { - "babel-cli": "^6.24.0", - "babel-preset-latest": "^6.24.0", - "coveralls": "^2.13.0", - "jest": "^19.0.2" - }, - "engines": { - "node": ">=0.4.0" - }, - "bugs": { - "url": "https://github.com/jpmonette/feed/issues" - }, - "repository": { - "type": "git", - "url": "https://github.com/jpmonette/feed.git" - } -} +{ + "name": "feed", + "version": "1.0.2", + "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 ", + "contributors": [ + { + "name": "Pierre Galvez", + "email": "contact@pierre-galvez.fr" + } + ], + "license": "MIT", + "main": "lib/feed.js", + "scripts": { + "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" + }, + "jest": { + "verbose": true, + "collectCoverage": true, + "collectCoverageFrom": [ + "**/src/*.{js}" + ], + "testMatch": [ + "**/*.spec.js" + ] + }, + "keywords": [ + "rss", + "atom", + "feed", + "syndication", + "xml", + "wrapper", + "blog" + ], + "dependencies": { + "mime-types": "^2.1.15", + "xml": ">= 0.0.5" + }, + "devDependencies": { + "babel-cli": "^6.24.0", + "babel-preset-latest": "^6.24.0", + "coveralls": "^2.13.0", + "jest": "^19.0.2" + }, + "engines": { + "node": ">=0.4.0" + }, + "bugs": { + "url": "https://github.com/jpmonette/feed/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/jpmonette/feed.git" + } +} diff --git a/src/feed.js b/src/feed.js index 67b7bb4..26a060e 100644 --- a/src/feed.js +++ b/src/feed.js @@ -1,5 +1,5 @@ import xml from 'xml' -import path from 'path' +import mime from 'mime-types' const GENERATOR = 'Feed for Node.js' const DOCTYPE = '\n' @@ -354,8 +354,12 @@ class Feed { } if(entry.image) { - var imgExt = path.extname(entry.image).substr(1); - item.push({ enclosure: [{ _attr: { url: entry.image, type: 'image/'+imgExt } }] }); + let attr = { url: entry.image }; + let contentType = mime.lookup(entry.image); + if(contentType && contentType.indexOf('image/')==0) { + attr.type = contentType; + } + item.push({ enclosure: [{ _attr: attr }] }); } channel.push({ item }); diff --git a/src/feed.spec.js b/src/feed.spec.js index f2a2dac..5e0eefb 100644 --- a/src/feed.spec.js +++ b/src/feed.spec.js @@ -79,6 +79,8 @@ test('it should generate an RSS 2.0 feed', () => { Sat, 13 Jul 2013 23:00:00 GMT janedoe@example.com (Jane Doe) + + `; From cd9d0e42828c8f665d3144c5d97b246c69fae9cd Mon Sep 17 00:00:00 2001 From: Jean-Philippe Monette Date: Sun, 21 May 2017 21:56:45 -0400 Subject: [PATCH 5/5] Update package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 179cd90..fb429ed 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "blog" ], "dependencies": { - "mime-types": "^2.1.15", "xml": ">= 0.0.5" }, "devDependencies": {