18 Commits

Author SHA1 Message Date
LightAir
9cccd65768 Обновление версии пакета 2021-06-09 22:27:19 +03:00
LightAir
812a429d9b Удаление лишних dev пакетов. Удаление dev пакетов с уязвимостями 2021-06-09 22:17:08 +03:00
LightAir
15c9715cee Merge pull request #6 from Armanio/patch-1
chore(docs): typo fix in readme
2021-06-04 21:47:12 +03:00
Arman
816b6b5690 chore(docs): typo fix in readme 2021-06-04 15:17:36 +03:00
LightAir
ef90f974bd Изменение тестов 2020-12-15 22:51:02 +03:00
LightAir
8aa086865d Изменение тестов 2020-12-15 22:47:51 +03:00
LightAir
6d3cd71f47 Правки версии пакета 2020-12-02 00:40:28 +03:00
LightAir
ec44f8e5d3 Небольшие изменения 2020-12-02 00:32:13 +03:00
LightAir
7770e925fd Добавление новых версий ноды в travis ci 2020-12-01 23:54:04 +03:00
LightAir
9864d6408a Небольшие правки. Добавил тесты на новый функционал от crackosok 2020-12-01 23:49:41 +03:00
LightAir
3d5258a6c7 Merge pull request #4 from crackosok/master
add possibility to set turbo false
2020-12-01 20:21:44 +03:00
Kirill Myagkikh
a8e4ba436c review fixes 2020-11-29 19:20:10 +05:00
Kirill Myagkikh
acd60d5922 add possibility to set turbo false 2020-11-18 15:23:38 +05:00
cfea55ea4c Merge pull request #3 from concertmoscow/goals
Added turbo:goal support
2020-09-02 10:28:48 +03:00
vvm
93815ec708 1.1.0 2020-08-31 23:16:13 +03:00
vvm
c5a7ff6e1c Added turbo:goal support 2020-08-31 23:08:53 +03:00
LightAir
2d3f75902f Косметические изменения 2018-05-30 22:47:30 +03:00
LightAir
d896040f63 Рабочая версия 2018-05-30 22:20:54 +03:00
13 changed files with 216 additions and 143 deletions

View File

@@ -13,9 +13,4 @@ after_script:
- codeclimate-test-reporter < ./coverage/lcov.info
matrix:
include:
- node_js: '8.11.2'
before_install: npm -g i npm@2
- node_js: '6.11.2'
before_install: npm -g i npm@2
- node_js: '10.2.1'
before_install: npm -g i npm@2
- node_js: 'lts/*'

View File

@@ -4,11 +4,12 @@ const xml = require('xml');
/**
* Check first argument. If true - push last argument to second argument
*
* @param condition
* @param array
* @param data
*/
function ifTruePush(condition, array, data) {
function pushIfConditionTrue(condition, array, data) {
if (condition) {
array.push(data);
}
@@ -17,9 +18,9 @@ function ifTruePush(condition, array, data) {
/**
* @param related
* @param itemValues
* @param relatedfinity
* @param relatedInfinity
*/
function addRelated(related, itemValues, relatedfinity) {
function addRelated(related, itemValues, relatedInfinity) {
let relatedResult = related.map(function (rel) {
return {
link: [{
@@ -31,13 +32,32 @@ function addRelated(related, itemValues, relatedfinity) {
};
});
if (relatedfinity) {
if (relatedInfinity) {
relatedResult.push({
_attr: {'type': 'infinity'}
});
}
ifTruePush(related, itemValues, {'yandex:related': relatedResult});
pushIfConditionTrue(related, itemValues, {'yandex:related': relatedResult});
}
/**
* @param item
* @param itemValues
*/
function pushGoals(item, itemValues) {
if (item.goals.length > 0) {
item.goals.forEach(goal => itemValues.push({
'turbo:goal': {
_attr: {
type: goal.type || 'yandex',
'turbo-goal-id': goal.id,
name: goal.name,
id: goal.counter_id,
}
}
}));
}
}
/**
@@ -47,34 +67,38 @@ function addRelated(related, itemValues, relatedfinity) {
*/
function items(items, channel) {
items.forEach(function (item) {
let item_values = [];
item_values.push({_attr: {'turbo': 'true'}});
item_values.push({link: item.url});
item_values.push({'turbo:source': item.url});
let itemValues = [];
itemValues.push({_attr: {'turbo': item.turboEnabled ? 'true' : 'false'}});
itemValues.push({link: item.url});
ifTruePush(item.date, item_values, {pubDate: new Date(item.date).toUTCString()});
ifTruePush(item.author, item_values, {author: item.author});
pushIfConditionTrue(item.turboSource, itemValues, {'turbo:source': item.turboSource});
pushIfConditionTrue(item.turboTopic, itemValues, {'turbo:topic': item.turboTopic});
pushIfConditionTrue(item.date, itemValues, {pubDate: new Date(item.date).toUTCString()});
pushIfConditionTrue(item.author, itemValues, {author: item.author});
let img = '';
let menu = '';
let img = '', menu = '';
if (item.image_url) {
img = '<figure><img src="' + item.image_url + '" /></figure>';
}
if (item.menu) {
menu = '<menu>' + item.menu + '</menu>';
if (Array.isArray(item.menu)) {
menu = '<menu>' + item.menu.map(function (item) {
return '<a href="' + item.link + '">' + item.text + '</a>';
}).join('') + '</menu>';
}
let fullContent = '<header>' + img + ' <h1>' + item.title + '</h1>' + menu + '</header>' + item.content;
item_values.push({'turbo:content': {_cdata: fullContent}});
pushGoals(item, itemValues);
itemValues.push({'turbo:content': {_cdata: fullContent}});
if (typeof item.related !== 'undefined') {
addRelated(item.related, item_values, item.relatedfinity);
addRelated(item.related, itemValues, item.relatedfinity);
}
channel.push({item: item_values});
channel.push({item: itemValues});
});
}
@@ -87,9 +111,9 @@ function generateXML(data) {
let channel = [];
channel.push({title: {_cdata: data.title}});
channel.push({link: data.link || 'http://github.com/LightAir/turbo-rss'});
channel.push({link: data.link});
channel.push({description: {_cdata: data.description || data.title}});
channel.push({language: 'ru'});
channel.push({language: data.language});
items(data.items, channel);
@@ -109,35 +133,46 @@ function generateXML(data) {
}
/**
* Base function
* @param options
* @param items
* @constructor
* @param data
* @returns {*}
*/
function YTurbo(options, items) {
options = options || {};
this.title = options.title || 'Untitled';
this.description = options.description || '';
this.link = options.link;
this.items = items || [];
this.item = function (data) {
data = data || {};
let item = {
title: data.title || 'No title',
function itemData(data) {
return {
title: data.title || '',
description: data.description || '',
image_url: data.image_url,
url: data.url,
url: data.url || data.link,
author: data.author,
date: data.date || data.pubDate,
content: data.content,
menu: data.menu,
related: data.related,
relatedfinity: data.relatedfinity || false,
turboSource: data.turboSource || '',
turboTopic: data.turboTopic || '',
goals: data.goals || [],
turboEnabled: data.turboEnabled !== undefined ? data.turboEnabled: true,
};
}
/**
* Base function
* @param options
* @param items
* @constructor
*/
function TR(options, items) {
options = options || {};
this.items.push(item);
this.title = options.title || '';
this.link = options.link || '';
this.description = options.description || '';
this.language = options.language || 'ru';
this.items = items || [];
this.item = function (data) {
data = data || {};
this.items.push(itemData(data));
return this;
};
@@ -146,4 +181,4 @@ function YTurbo(options, items) {
};
}
module.exports = YTurbo;
module.exports = TR;

View File

@@ -1,6 +1,6 @@
{
"name": "turbo-rss",
"version": "1.0.7",
"version": "1.2.2",
"description": "RSS based, feed generator for Yandex turbo",
"keywords": [
"yandex",
@@ -10,8 +10,7 @@
],
"main": "lib/index",
"scripts": {
"test": "tape test --tap | tap-difflet",
"coverage": "istanbul cover tape test -- -R spec"
"test": "tape test --tap | tap-min"
},
"homepage": "https://github.com/LightAir/turbo-rss",
"author": {
@@ -20,6 +19,7 @@
},
"contributors": [
"LightAir <public@softroot.ru>",
"Ivan Pilyugin (aka Archer)",
"Dylan Greene <dylang@gmail.com>",
"Xavier Damman <xdamman@gmail.com>",
"Michael R. Lange",
@@ -55,27 +55,12 @@
"xml": "1.0.1"
},
"devDependencies": {
"eslint": "^4.19.1",
"folderify": "^1.1.0",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "^0.11.3",
"grunt-release": "^0.13.0",
"grunt-templates-dylang": "^1.0.10",
"eslint": "^7.28.0",
"include-folder": "^1.0.0",
"load-grunt-tasks": "^3.3.0",
"mockdate": "^1.0.3",
"prova": "^2.1.2",
"q": "^1.4.1",
"tap-difflet": "^0.4.0",
"tape": "^4.2.1",
"time-grunt": "^1.2.1",
"xml2js": "^0.4.12"
},
"browserify": {
"transform": [
"folderify"
]
"mockdate": "^3.0.5",
"q": "^1.5.1",
"tap-min": "~2.0.0",
"tape": "^5.2.2"
},
"license": "MIT"
}

View File

@@ -1,5 +1,3 @@
## WIP
## turbo-rss
[![Maintainability](https://api.codeclimate.com/v1/badges/6525d2aabf20185b68b6/maintainability)](https://codeclimate.com/github/LightAir/turbo-rss/maintainability)
@@ -8,9 +6,7 @@
[![npm](https://img.shields.io/badge/npm%20package-1.0.7-blue.svg?longCache=true&style=flat)](https://www.npmjs.com/package/turbo-rss)
![license](https://img.shields.io/packagist/l/doctrine/orm.svg?longCache=true&style=flat)
>Генератор RSS разметки для сервиса Турбо-страницы
>ПРЕДУПРЕЖДЕНИЕ! Работа в процессе
>Генератор RSS разметки для сервиса Турбо-страницы https://yandex.ru/support/webmaster/turbo/connection.html
### Использование
@@ -25,12 +21,11 @@ var feed = new TR(feedOptions);
##### `Опции канала`
* `title` **string** Название RSS-канала.
* `description` _optional_ **string** Описание канала одним предложением. Не используйте HTML-разметку..
* `author` _optional_ **string** If included it is the name of the item's creator. **(Будет удалено)**
* `link` **url string** Домен сайта, данные которого транслируются..
* `pubDate` _optional_ **Date object or date string** The publication date for content in the feed **(Будет удалено)**
* `link` **url string** Домен сайта, данные которого транслируются.
* `description` _optional_ **string** Описание канала одним предложением. Не используйте HTML-разметку.
* `language` _optional_ **string** Язык статьи по стандарту ISO 639-1. По умолчанию ru.
*Будет добавлено в новых версиях turbo:analytics, turbo:adNetwork*
*Будет добавлено в новых версиях turbo:analytics, turbo:adNetwork, на текущий момент можно добавить в интерфейсе Яндекс Вебмастер*
#### Добавление страницы в канал
```js
@@ -40,22 +35,30 @@ feed.item(itemOptions);
##### itemOptions
* `title` **string** Заголовок страницы.
* `image_url` **url string** Адрес изображения, которое используется в качестве обложки. Изображение может быть в любом формате.
* `url` **url string** URL страницы сайта, для которой нужно сформировать Турбо-страницу.
* `image_url` _optional_ **url string** Адрес изображения, которое используется в качестве обложки. Изображение может быть в любом формате.
* `link` **url string** URL страницы сайта, для которой нужно сформировать Турбо-страницу.
* `author` _optional_ **string** Автор статьи, размещенной на странице.
* `date` **string** Время публикации контента на сайте источника.
* `date` или `pubDate` **string** Время публикации контента на сайте источника. Передается в формате RFC-822.
* `content` **string** Содержимое страницы
* `related` _optional_ **array** Аффилированные ссылки `yandex:related` в конце статьи.
* `menu` _optional_ **array** Внимание! Меню будет отображаться только в том случае, если в настройках на странице Яндекс Вебмастер -> Турбо-страницы -> Настройки, содержимое 'Меню Турбо-страниц' пустое!
* `related` _optional_ **array** Аффилированные ссылки `yandex:related` в конце статьи. Вы можете разместить ссылки на другие ресурсы или настроить отображение непрерывной ленты статей, реализованной, например с помощью AJAX.
* `relatedfinity` _optional_ **bool** Непрерывная лента статей
* `turboSource` _optional_ **string** URL страницы-источника, который можно передать в Яндекс.Метрику.
* `turboTopic` _optional_ **string** Заголовок страницы, который можно передать в Яндекс.Метрику.
* `goals` _optional_ **array** массив типа: { _id_ - внутренний идентификатор цели (turbo-goal-id), _name_ - имя цели, _counter_id_ - id счётчика яндекс-метрики }
* `turboEnabled`_optional_ **bool** Принудительная установка атрибута "turbo". По умолчанию true. Установка в false позволит скрыть отображение турбо-страницы
###### menu array
menu должен содержать массив объектов со следующими опциями:
*Будет добавлено в новых версиях turbo:source, turbo:topic, menu, pubDate как алиас date*
* `link` **url string** ссылка
* `text` **string** текст ссылки. не должен содержать html
###### related array
related должен содержать массив объектов со следующими опциями:
* `link` **string** ссылка на статью'
* `image_url` **string** ссылка на изображение к статье
* `text` **string** текст ссылки
* `link` **url string** ссылка на статью
* `image_url` **url string** ссылка на изображение к статье
* `text` **string** текст ссылки. Не должен содержать html
##### Получение XML
@@ -69,14 +72,12 @@ var xml = feed.xml();
```js
var TR = require('turbo-rss');
/* lets create feed */
var feed = new TR({
title: 'title',
description: 'description',
link: 'http://example.com',
});
/* loop over data and add to feed */
feed.item({
title: 'item title',
image_url: 'http://example.com/example.png',
@@ -84,6 +85,19 @@ feed.item({
author: 'LightAir',
date: 'May 27, 2012',
content: '<p>hello</p>',
goals: [{
type: "yandex",
id: "turbo-goal-id",
counter_id: "12345",
name: "order",
}],
menu: [{
link: 'http://example.com/',
text: 'Главная'
}, {
link: 'http://example.com/about',
text: 'О сайте'
}],
related: [{
link: 'http://example.com/related/post1',
image_url: 'http://example.com/i/img1.jpg',
@@ -95,14 +109,21 @@ feed.item({
}]
});
// cache the xml to send to clients
var xml = feed.xml();
```
## Тестирование
Для запуска тестов выполните `npm test`. На текущий момен покрытие тестами не 100%
Для запуска тестов выполните `npm test`.
```sh
$ npm test
```
## Спасибо
@jahglow
@vvmspace
@crackosok

View File

@@ -1 +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[Untitled]]></title><link>http://github.com/LightAir/turbo-rss</link><description><![CDATA[Untitled]]></description><language>ru</language></channel></rss>
<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/><link></link><description/><language>ru</language></channel></rss>

View File

@@ -1 +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></link><turbo:source></turbo:source><turbo:content><![CDATA[<header> <h1>No title</h1></header>undefined]]></turbo:content></item></channel></rss>
<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></link><turbo:content><![CDATA[<header> <h1></h1></header>undefined]]></turbo:content></item></channel></rss>

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="false"><link></link><turbo:content><![CDATA[<header> <h1></h1></header>undefined]]></turbo:content></item></channel></rss>

View File

@@ -1 +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[Untitled]]></title><link>http://github.com/LightAir/turbo-rss</link><description><![CDATA[Untitled]]></description><language>ru</language><item turbo="true"><link></link><turbo:source></turbo:source><turbo:content><![CDATA[<header> <h1>No title</h1></header>undefined]]></turbo:content></item></channel></rss>
<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/><link></link><description/><language>ru</language><item turbo="true"><link></link><turbo:content><![CDATA[<header> <h1></h1></header>undefined]]></turbo:content></item></channel></rss>

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><pubDate>Sat, 26 May 2018 21:00:00 GMT</pubDate><author>vvm.space</author><turbo:goal type="yandex" turbo-goal-id="turbo-goal-id" name="order" id="12345"/><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>

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><pubDate>Sat, 26 May 2018 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><menu><a href="http://example.com/">Главная</a><a href="http://example.com/about">О сайте</a></menu></header><p>hello</p>]]></turbo:content><yandex:related type="infinity"><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><item turbo="true"><link></link><turbo:content><![CDATA[<header> <h1></h1></header>undefined]]></turbo:content></item></channel></rss>

View File

@@ -1 +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 2018 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><menu><a href="http://example.com/page1.html">Текст ссылки</a> <a href="http://example.com/page2.html">Текст ссылки</a></menu></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>
<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><pubDate>Sat, 26 May 2018 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>

View File

@@ -1 +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 2018 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 type="infinity"><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>
<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><pubDate>Sat, 26 May 2018 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 type="infinity"><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>

View File

@@ -1,17 +1,31 @@
// prova is a wrapper for tape
// use npm run test:browser to run tests in a browser
const test = require('tape');
const YTurbo = require('..');
const TR = require('..');
const includeFolder = require('include-folder');
const expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
const baseOptions = {
title: 'title',
description: 'description',
link: 'http://example.com/rss.xml',
site_url: 'http://example.com'
};
const relatedOptions = [{
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'
}];
require('mockdate').set('Wed, 10 Dec 2014 19:04:57 GMT');
test('empty feed', function (t) {
t.plan(2);
let feed = new YTurbo();
let feed = new TR();
t.equal(feed.xml(), expectedOutput.default.trim());
feed.item();
t.equal(feed.xml(), expectedOutput.defaultOneItem.trim());
@@ -19,12 +33,7 @@ test('empty feed', function(t) {
test('default 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'
});
let feed = new TR(baseOptions);
feed.item({});
@@ -33,12 +42,7 @@ test('default item', function(t) {
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'
});
let feed = new TR(baseOptions);
feed.item({
title: 'item title',
@@ -48,15 +52,7 @@ test('related item', function(t) {
date: 'May 27, 2018 00:00 AM',
menu: '<a href="http://example.com/page1.html">Текст ссылки</a> <a href="http://example.com/page2.html">Текст ссылки</a>',
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'
}]
related: relatedOptions
});
t.equal(feed.xml(), expectedOutput.relatedItem.trim());
@@ -64,12 +60,7 @@ test('related item', function(t) {
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'
});
let feed = new TR(baseOptions);
feed.item({
title: 'item title',
@@ -79,16 +70,59 @@ test('related item', function(t) {
date: 'May 27, 2018 00:00 AM',
content: '<p>hello</p>',
relatedfinity: true,
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'
}]
related: relatedOptions
});
t.equal(feed.xml(), expectedOutput.relatedItemInfinity.trim());
});
test('menu', function (t) {
t.plan(1);
let feed = new TR(baseOptions);
feed.item({
title: 'item title',
image_url: 'http://example.com/example.png',
url: 'http://example.com/article4?this&that',
author: 'LightAir',
date: 'May 27, 2018 00:00 AM',
content: '<p>hello</p>',
relatedfinity: true,
menu: [{
link: 'http://example.com/',
text: 'Главная',
}, {
link: 'http://example.com/about',
text: 'О сайте',
}],
related: relatedOptions
});
feed.item({});
t.equal(feed.xml(), expectedOutput.menu.trim());
});
test('goals', function (t) {
t.plan(1);
let feed = new TR(baseOptions);
feed.item({
title: 'item title',
image_url: 'http://example.com/example.png',
url: 'http://example.com/article4?this&that',
author: 'vvm.space',
date: 'May 27, 2018 00:00 AM',
menu: '<a href="http://example.com/page1.html">Текст ссылки</a> <a href="http://example.com/page2.html">Текст ссылки</a>',
goals: [{
type: 'yandex',
id: 'turbo-goal-id',
counter_id: '12345',
name: 'order',
}],
content: '<p>hello</p>',
related: relatedOptions
});
t.equal(feed.xml(), expectedOutput.goal.trim());
});