Skip to content

Commit

Permalink
Dont auto generate last build date
Browse files Browse the repository at this point in the history
  • Loading branch information
sathis authored and alexjorgef committed May 10, 2022
1 parent 5e6014c commit 376ce5b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function generateXML (data){
channel.push({ image: [ {url: data.image_url}, {title: data.title}, {link: data.site_url} ] });
}
channel.push({ generator: data.generator });
channel.push({ lastBuildDate: new Date().toUTCString() });
if (!data.omitBuildDate) {
channel.push({ lastBuildDate: new Date().toUTCString() });
}

ifTruePush(data.feed_url, channel, { 'atom:link': { _attr: { href: data.feed_url, rel: 'self', type: 'application/rss+xml' } } });
ifTruePush(data.author, channel, { 'author': { _cdata: data.author } });
Expand Down Expand Up @@ -159,6 +161,7 @@ function RSS (options, items) {
this.custom_namespaces = options.custom_namespaces || {};
this.custom_elements = options.custom_elements || [];
this.items = items || [];
this.omitBuildDate = options.omitBuildDate || false;

this.item = function (options) {
options = options || {};
Expand Down
9 changes: 9 additions & 0 deletions test/expectedOutput/omitBuildDate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title><![CDATA[title]]></title>
<description><![CDATA[description]]></description>
<link>http://example.com</link>
<generator>RSS for Node</generator>
<atom:link href="http://example.com/rss.xml" rel="self" type="application/rss+xml"/>
</channel>
</rss>
14 changes: 14 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,17 @@ test('custom namespaces', function(t) {

t.equal(feed.xml({indent: true}), expectedOutput.customNamespaces);
});

test('omit build date', function(t) {
t.plan(1);

var feed = new RSS({
title: 'title',
description: 'description',
feed_url: 'http://example.com/rss.xml',
site_url: 'http://example.com',
omitBuildDate: true
});

t.equal(feed.xml({indent: true}), expectedOutput.omitBuildDate);
});

0 comments on commit 376ce5b

Please sign in to comment.