Comparing version 4.0.0 to 4.1.0
@@ -77,2 +77,8 @@ "use strict"; | ||
} | ||
if (Array.isArray(item.category)) { | ||
entry.category = []; | ||
item.category.map(function (category) { | ||
entry.category.push(formatCategory(category)); | ||
}); | ||
} | ||
if (item.contributor && Array.isArray(item.contributor)) { | ||
@@ -102,2 +108,12 @@ entry.contributor = []; | ||
}; | ||
var formatCategory = function (category) { | ||
var name = category.name, scheme = category.scheme, term = category.term; | ||
return { | ||
_attributes: { | ||
label: name, | ||
scheme: scheme, | ||
term: term | ||
} | ||
}; | ||
}; | ||
//# sourceMappingURL=atom1.js.map |
@@ -69,2 +69,10 @@ "use strict"; | ||
} | ||
if (Array.isArray(item.category)) { | ||
feedItem.tags = []; | ||
item.category.map(function (category) { | ||
if (category.name) { | ||
feedItem.tags.push(category.name); | ||
} | ||
}); | ||
} | ||
if (item.extensions) { | ||
@@ -71,0 +79,0 @@ item.extensions.map(function (e) { |
@@ -18,3 +18,3 @@ "use strict"; | ||
lastBuildDate: { _text: options.updated ? options.updated.toUTCString() : new Date().toUTCString() }, | ||
docs: { _text: "http://blogs.law.harvard.edu/tech/rss" }, | ||
docs: { _text: options.docs ? options.docs : "https://validator.w3.org/feed/docs/rss2.html" }, | ||
generator: { _text: options.generator || config_1.generator } | ||
@@ -80,2 +80,5 @@ } | ||
} | ||
else if (entry.id) { | ||
item.guid = { _text: entry.id }; | ||
} | ||
else if (entry.link) { | ||
@@ -102,2 +105,8 @@ item.guid = { _text: entry.link }; | ||
} | ||
if (Array.isArray(entry.category)) { | ||
item.category = []; | ||
entry.category.map(function (category) { | ||
item.category.push(formatCategory(category)); | ||
}); | ||
} | ||
if (entry.image) { | ||
@@ -116,2 +125,11 @@ item.enclosure = { _attributes: { url: entry.image } }; | ||
}); | ||
var formatCategory = function (category) { | ||
var name = category.name, domain = category.domain; | ||
return { | ||
_text: name, | ||
_attributes: { | ||
domain: domain | ||
} | ||
}; | ||
}; | ||
//# sourceMappingURL=rss2.js.map |
@@ -8,2 +8,3 @@ export interface Item { | ||
content?: string; | ||
category?: Category[]; | ||
guid?: string; | ||
@@ -22,2 +23,8 @@ image?: string; | ||
} | ||
export interface Category { | ||
name?: string; | ||
domain?: string; | ||
scheme?: string; | ||
term?: string; | ||
} | ||
export interface FeedOptions { | ||
@@ -32,2 +39,3 @@ id: string; | ||
hub?: string; | ||
docs?: string; | ||
author?: Author; | ||
@@ -34,0 +42,0 @@ link?: string; |
{ | ||
"name": "feed", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Feed is a RSS, Atom and JSON feed generator for Node.js, making content syndication simple and intuitive!", | ||
@@ -11,3 +11,3 @@ "homepage": "https://github.com/jpmonette/feed", | ||
"scripts": { | ||
"build": "rm -rf lib/ && mkdir lib && tsc", | ||
"build": "rimraf lib/ && mkdir lib && tsc", | ||
"prepublish": "npm run build", | ||
@@ -14,0 +14,0 @@ "test": "export NODE_ENV=test && jest --silent", |
@@ -34,3 +34,3 @@ import { Feed } from "../feed"; | ||
title: "Hello World", | ||
id: "https://example.com/hello-world", | ||
id: "419c523a-28f4-489c-877e-9604be64c002", | ||
link: "https://example.com/hello-world", | ||
@@ -79,2 +79,11 @@ description: "This is an article about Hello World.", | ||
], | ||
category: [ | ||
{ | ||
name: 'Grateful Dead' | ||
}, | ||
{ | ||
name: 'MSFT', | ||
domain: 'http://www.fool.com/cusips' | ||
} | ||
], | ||
date: updated, | ||
@@ -81,0 +90,0 @@ image: "https://example.com/hello-world.jpg", |
import { generator } from "./config"; | ||
import * as convert from "xml-js"; | ||
import { Feed } from "./feed"; | ||
import { Author, Item } from "./typings"; | ||
import { Author, Item, Category } from "./typings"; | ||
@@ -129,3 +129,10 @@ export default (ins: Feed) => { | ||
// category | ||
if (Array.isArray(item.category)) { | ||
entry.category = []; | ||
item.category.map((category: Category) => { | ||
entry.category.push(formatCategory(category)); | ||
}); | ||
} | ||
// contributor | ||
@@ -167,1 +174,13 @@ if (item.contributor && Array.isArray(item.contributor)) { | ||
}; | ||
const formatCategory = (category: Category) => { | ||
const { name, scheme, term } = category; | ||
return { | ||
_attributes: { | ||
label: name, | ||
scheme, | ||
term | ||
} | ||
}; | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { Extension, Item, Author } from "./typings"; | ||
import { Extension, Item, Author, Category } from "./typings"; | ||
import { Feed } from "./feed"; | ||
@@ -85,2 +85,11 @@ | ||
if (Array.isArray(item.category)) { | ||
feedItem.tags = []; | ||
item.category.map((category: Category) => { | ||
if (category.name) { | ||
feedItem.tags.push(category.name); | ||
} | ||
}); | ||
} | ||
if (item.extensions) { | ||
@@ -87,0 +96,0 @@ item.extensions.map((e: Extension) => { |
import * as convert from "xml-js"; | ||
import { generator } from "./config"; | ||
import { Feed } from "./feed"; | ||
import { Item, Author } from "./typings"; | ||
import { Item, Author, Category } from "./typings"; | ||
@@ -20,3 +20,3 @@ export default (ins: Feed) => { | ||
lastBuildDate: { _text: options.updated ? options.updated.toUTCString() : new Date().toUTCString() }, | ||
docs: { _text: "http://blogs.law.harvard.edu/tech/rss" }, | ||
docs: { _text: options.docs ? options.docs : "https://validator.w3.org/feed/docs/rss2.html" }, | ||
generator: { _text: options.generator || generator } | ||
@@ -37,3 +37,3 @@ } | ||
* Channel Image | ||
* http://cyber.law.harvard.edu/rss/rss.html#ltimagegtSubelementOfLtchannelgt | ||
* https://validator.w3.org/feed/docs/rss2.html#ltimagegtSubelementOfLtchannelgt | ||
*/ | ||
@@ -50,3 +50,3 @@ if (options.image) { | ||
* Channel Copyright | ||
* http://cyber.law.harvard.edu/rss/rss.html#optionalChannelElements | ||
* https://validator.w3.org/feed/docs/rss2.html#optionalChannelElements | ||
*/ | ||
@@ -59,3 +59,3 @@ if (options.copyright) { | ||
* Channel Categories | ||
* http://cyber.law.harvard.edu/rss/rss.html#comments | ||
* https://validator.w3.org/feed/docs/rss2.html#comments | ||
*/ | ||
@@ -106,3 +106,3 @@ ins.categories.map(category => { | ||
* Channel Categories | ||
* http://cyber.law.harvard.edu/rss/rss.html#hrelementsOfLtitemgt | ||
* https://validator.w3.org/feed/docs/rss2.html#hrelementsOfLtitemgt | ||
*/ | ||
@@ -124,2 +124,4 @@ base.rss.channel.item = []; | ||
item.guid = { _text: entry.guid }; | ||
} else if (entry.id) { | ||
item.guid = { _text: entry.id }; | ||
} else if (entry.link) { | ||
@@ -143,3 +145,3 @@ item.guid = { _text: entry.link }; | ||
* Item Author | ||
* http://cyber.law.harvard.edu/rss/rss.html#ltauthorgtSubelementOfLtitemgt | ||
* https://validator.w3.org/feed/docs/rss2.html#ltauthorgtSubelementOfLtitemgt | ||
*/ | ||
@@ -154,2 +156,12 @@ if (Array.isArray(entry.author)) { | ||
} | ||
/** | ||
* Item Category | ||
* https://validator.w3.org/feed/docs/rss2.html#ltcategorygtSubelementOfLtitemgt | ||
*/ | ||
if (Array.isArray(entry.category)) { | ||
item.category = []; | ||
entry.category.map((category: Category) => { | ||
item.category.push(formatCategory(category)); | ||
}); | ||
} | ||
@@ -172,1 +184,12 @@ if (entry.image) { | ||
}; | ||
const formatCategory = (category: Category) => { | ||
const { name, domain } = category; | ||
return { | ||
_text: name, | ||
_attributes: { | ||
domain | ||
} | ||
}; | ||
}; | ||
@@ -9,2 +9,3 @@ export interface Item { | ||
content?: string; | ||
category?: Category[]; | ||
@@ -30,2 +31,9 @@ guid?: string; | ||
export interface Category { | ||
name?: string; | ||
domain?: string; | ||
scheme?: string; | ||
term?: string; | ||
} | ||
export interface FeedOptions { | ||
@@ -41,2 +49,3 @@ id: string; | ||
hub?: string; | ||
docs?: string; | ||
@@ -43,0 +52,0 @@ author?: Author; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
47
1056
75463