13 Commits
1.0.3 ... 1.0.5

Author SHA1 Message Date
LightAir
c5a9e4b5fd Merge pull request #2 from jahglow/master
corrected readme, ++patch
2018-05-29 11:01:54 +03:00
la
97e23fe031 Стилизация. Добавление теста для related 2018-05-29 11:00:33 +03:00
Ivan Pilyugin (aka Archer)
a4b18cde97 added yandex:related 2018-05-29 10:35:37 +03:00
Ivan Pilyugin (aka Archer)
1dca86ab85 corrected readme for yandex:related 2018-05-29 10:34:55 +03:00
Ivan Pilyugin (aka Archer)
8b4ec85bcf Merge pull request #1 from LightAir/master
Merge pull request #1 from jahglow/master
2018-05-29 10:32:52 +03:00
LightAir
b02eaab7e6 Merge pull request #1 from jahglow/master
Базовая поддержка yandex:related
2018-05-29 10:07:16 +03:00
Ivan Pilyugin (aka Archer)
10e74b0a1b yandex:related image renamed to image_url
for naming consistency
2018-05-29 10:04:50 +03:00
Ivan Pilyugin (aka Archer)
c47a6d3d0f Update readme.md
added description to yandex:related
2018-05-29 10:03:41 +03:00
Ivan Pilyugin (aka Archer)
365abd5592 added yandex:related support 2018-05-29 09:58:53 +03:00
la
8bd429accc Приведение в порядок соответствия версий npm и git 2018-05-03 13:55:28 +03:00
la
43dadcd891 Merge branch 'master' of github.com:LightAir/turbo-rss 2018-05-03 13:53:40 +03:00
la
e4b5093678 npm 1.0.3 2018-05-03 13:52:59 +03:00
LightAir
28030cd0dc Update readme.md 2018-05-03 13:37:38 +03:00
5 changed files with 67 additions and 17 deletions

View File

@@ -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);

View File

@@ -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",

View File

@@ -2,7 +2,7 @@
## turbo-rss ## turbo-rss
[![Build Status](https://travis-ci.org/LightAir/turbo-rss.svg)](https://travis-ci.org/lightair/turbo-rss) [![Build Status](https://travis-ci.org/LightAir/turbo-rss.svg)](https://travis-ci.org/LightAir/turbo-rss)
![npm](https://img.shields.io/npm/v/npm.svg) ![npm](https://img.shields.io/npm/v/npm.svg)
![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg) ![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg)
@@ -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

View 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&amp;that</link><turbo:source>http://example.com/article4?this&amp;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>&lt;link url=&quot;http://example.com/related/post1&quot; img=&quot;http://example.com/i/img1.jpg&quot;&gt;related link text 1&lt;/link&gt;&lt;link url=&quot;http://example.com/related/post2&quot; img=&quot;http://example.com/i/img2.jpg&quot;&gt;related link text 2&lt;/link&gt;</yandex:related></item></channel></rss>

View File

@@ -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());
});