mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 12:06:20 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5a9e4b5fd | ||
|
|
97e23fe031 | ||
|
|
a4b18cde97 | ||
|
|
1dca86ab85 | ||
|
|
8b4ec85bcf | ||
|
|
b02eaab7e6 | ||
|
|
10e74b0a1b | ||
|
|
c47a6d3d0f | ||
|
|
365abd5592 | ||
|
|
8bd429accc | ||
|
|
43dadcd891 | ||
|
|
e4b5093678 | ||
|
|
28030cd0dc |
13
lib/index.js
13
lib/index.js
@@ -43,6 +43,16 @@ function generateXML(data) {
|
|||||||
let fullContent = '<header>' + img + ' <h1>' + item.title + '</h1>' + menu + '</header>' + item.content;
|
let fullContent = '<header>' + img + ' <h1>' + item.title + '</h1>' + menu + '</header>' + item.content;
|
||||||
|
|
||||||
item_values.push({'turbo:content': {_cdata: fullContent}});
|
item_values.push({'turbo:content': {_cdata: fullContent}});
|
||||||
|
|
||||||
|
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});
|
channel.push({item: item_values});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -80,7 +90,8 @@ function YTurbo(options, items) {
|
|||||||
author: options.author,
|
author: options.author,
|
||||||
date: options.date || options.pubDate,
|
date: options.date || options.pubDate,
|
||||||
content: options.content,
|
content: options.content,
|
||||||
menu: options.menu
|
menu: options.menu,
|
||||||
|
related: options.related
|
||||||
};
|
};
|
||||||
|
|
||||||
this.items.push(item);
|
this.items.push(item);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "turbo-rss",
|
"name": "turbo-rss",
|
||||||
"version": "1.0.1",
|
"version": "1.0.5",
|
||||||
"description": "RSS based, feed generator for Yandex turbo",
|
"description": "RSS based, feed generator for Yandex turbo",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"yandex",
|
"yandex",
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
"lint": "grunt lint",
|
"lint": "grunt lint",
|
||||||
"test:browser": "prova -b"
|
"test:browser": "prova -b"
|
||||||
},
|
},
|
||||||
"homepage": "http://github.com/lightair/yandex-turbo",
|
"homepage": "https://github.com/LightAir/turbo-rss",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LightAir",
|
"name": "LightAir",
|
||||||
"email": "public@softroot.ru"
|
"email": "public@softroot.ru"
|
||||||
@@ -34,10 +34,10 @@
|
|||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://github.com/lightair/yandex-turbo.git"
|
"url": "https://github.com/LightAir/turbo-rss.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "http://github.com/lightair/yandex-turbo/issues"
|
"url": "https://github.com/LightAir/turbo-rss/issues"
|
||||||
},
|
},
|
||||||
"testling": {
|
"testling": {
|
||||||
"files": "test/*.js",
|
"files": "test/*.js",
|
||||||
|
|||||||
16
readme.md
16
readme.md
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## turbo-rss
|
## turbo-rss
|
||||||
|
|
||||||
[](https://travis-ci.org/lightair/turbo-rss)
|
[](https://travis-ci.org/LightAir/turbo-rss)
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
@@ -44,8 +44,9 @@ feed.item(itemOptions);
|
|||||||
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
||||||
* `date` **string** Время публикации контента на сайте источника.
|
* `date` **string** Время публикации контента на сайте источника.
|
||||||
* `content` **string** Содержимое страницы
|
* `content` **string** Содержимое страницы
|
||||||
|
* `related` _optional_ **object** Аффилированные ссылки `yandex:related` в конце статьи.
|
||||||
|
|
||||||
*Будет добавлено в новых версиях turbo:source, turbo:topic, yandex:related, menu, pubDate как алиас date*
|
*Будет добавлено в новых версиях turbo:source, turbo:topic, menu, pubDate как алиас date*
|
||||||
|
|
||||||
##### Получение XML
|
##### Получение XML
|
||||||
|
|
||||||
@@ -73,7 +74,16 @@ feed.item({
|
|||||||
url: 'http://example.com/article4?this&that',
|
url: 'http://example.com/article4?this&that',
|
||||||
author: 'LightAir',
|
author: 'LightAir',
|
||||||
date: 'May 27, 2012',
|
date: 'May 27, 2012',
|
||||||
content: '<p>hello</p>'
|
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'
|
||||||
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
// cache the xml to send to clients
|
// cache the xml to send to clients
|
||||||
|
|||||||
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
|
// prova is a wrapper for tape
|
||||||
// use npm run test:browser to run tests in a browser
|
// 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');
|
const includeFolder = require('include-folder');
|
||||||
var expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
|
const expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
|
||||||
|
|
||||||
require('mockdate').set('Wed, 10 Dec 2014 19:04:57 GMT');
|
require('mockdate').set('Wed, 10 Dec 2014 19:04:57 GMT');
|
||||||
|
|
||||||
test('empty feed', function(t) {
|
test('empty feed', function(t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
var feed = new YTurbo();
|
let feed = new YTurbo();
|
||||||
t.equal(feed.xml(), expectedOutput.default.trim());
|
t.equal(feed.xml(), expectedOutput.default.trim());
|
||||||
feed.item();
|
feed.item();
|
||||||
t.equal(feed.xml(), expectedOutput.defaultOneItem.trim());
|
t.equal(feed.xml(), expectedOutput.defaultOneItem.trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('default item', function(t) {
|
test('default item', function(t) {
|
||||||
|
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
|
let feed = new YTurbo({
|
||||||
var feed = new YTurbo({
|
|
||||||
title: 'title',
|
title: 'title',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
link: 'http://example.com/rss.xml',
|
link: 'http://example.com/rss.xml',
|
||||||
@@ -32,3 +30,33 @@ test('default item', function(t) {
|
|||||||
|
|
||||||
t.equal(feed.xml(), expectedOutput.defaultItem.trim());
|
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