mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 03:56:19 +00:00
Стилизация. Добавление теста для related
This commit is contained in:
24
lib/index.js
24
lib/index.js
@@ -44,21 +44,15 @@ function generateXML(data) {
|
||||
|
||||
item_values.push({'turbo:content': {_cdata: fullContent}});
|
||||
|
||||
let relatedLink = function(related) {
|
||||
return (
|
||||
'<link url="' +
|
||||
related.url +
|
||||
'" img="' +
|
||||
related.image_url +
|
||||
'">' +
|
||||
related.text +
|
||||
'</link>'
|
||||
);
|
||||
};
|
||||
ifTruePush(item.related, item_values, {
|
||||
'yandex:related': item.related.map(relatedLink).join('')
|
||||
});
|
||||
|
||||
if (typeof item.related !== "undefined") {
|
||||
ifTruePush(item.related, item_values, {
|
||||
'yandex:related': item.related.map(
|
||||
function (related) {
|
||||
return '<link url="' + related.link + '" img="' + related.image_url + '">' + related.text + '</link>';
|
||||
}
|
||||
).join('')
|
||||
});
|
||||
}
|
||||
channel.push({item: item_values});
|
||||
|
||||
});
|
||||
|
||||
1
test/expectedOutput/relatedItem.xml
Normal file
1
test/expectedOutput/relatedItem.xml
Normal file
@@ -0,0 +1 @@
|
||||
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" xmlns:turbo="http://turbo.yandex.ru" version="2.0"><channel><title><![CDATA[title]]></title><link>http://example.com/rss.xml</link><description><![CDATA[description]]></description><language>ru</language><item turbo="true"><link>http://example.com/article4?this&that</link><turbo:source>http://example.com/article4?this&that</turbo:source><pubDate>Sat, 26 May 2012 21:00:00 GMT</pubDate><author>LightAir</author><turbo:content><![CDATA[<header><figure><img src="http://example.com/example.png" /></figure> <h1>item title</h1></header><p>hello</p>]]></turbo:content><yandex:related><link url="http://example.com/related/post1" img="http://example.com/i/img1.jpg">related link text 1</link><link url="http://example.com/related/post2" img="http://example.com/i/img2.jpg">related link text 2</link></yandex:related></item></channel></rss>
|
||||
@@ -1,27 +1,25 @@
|
||||
// prova is a wrapper for tape
|
||||
// use npm run test:browser to run tests in a browser
|
||||
var test = require('tape');
|
||||
const test = require('tape');
|
||||
|
||||
var YTurbo = require('..');
|
||||
const YTurbo = require('..');
|
||||
|
||||
var includeFolder = require('include-folder');
|
||||
var expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
|
||||
const includeFolder = require('include-folder');
|
||||
const expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
|
||||
|
||||
require('mockdate').set('Wed, 10 Dec 2014 19:04:57 GMT');
|
||||
|
||||
test('empty feed', function(t) {
|
||||
t.plan(2);
|
||||
var feed = new YTurbo();
|
||||
let feed = new YTurbo();
|
||||
t.equal(feed.xml(), expectedOutput.default.trim());
|
||||
feed.item();
|
||||
t.equal(feed.xml(), expectedOutput.defaultOneItem.trim());
|
||||
});
|
||||
|
||||
test('default item', function(t) {
|
||||
|
||||
t.plan(1);
|
||||
|
||||
var feed = new YTurbo({
|
||||
let feed = new YTurbo({
|
||||
title: 'title',
|
||||
description: 'description',
|
||||
link: 'http://example.com/rss.xml',
|
||||
@@ -32,3 +30,33 @@ test('default item', function(t) {
|
||||
|
||||
t.equal(feed.xml(), expectedOutput.defaultItem.trim());
|
||||
});
|
||||
|
||||
test('related item', function(t) {
|
||||
t.plan(1);
|
||||
let feed = new YTurbo({
|
||||
title: 'title',
|
||||
description: 'description',
|
||||
link: 'http://example.com/rss.xml',
|
||||
site_url: 'http://example.com'
|
||||
});
|
||||
|
||||
feed.item({
|
||||
title: 'item title',
|
||||
image_url: 'http://example.com/example.png',
|
||||
url: 'http://example.com/article4?this&that',
|
||||
author: 'LightAir',
|
||||
date: 'May 27, 2012',
|
||||
content: '<p>hello</p>',
|
||||
related: [{
|
||||
link: 'http://example.com/related/post1',
|
||||
image_url: 'http://example.com/i/img1.jpg',
|
||||
text: 'related link text 1'
|
||||
}, {
|
||||
link: 'http://example.com/related/post2',
|
||||
image_url: 'http://example.com/i/img2.jpg',
|
||||
text: 'related link text 2'
|
||||
}]
|
||||
});
|
||||
|
||||
t.equal(feed.xml(), expectedOutput.relatedItem.trim());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user