4 Commits
1.0.8 ... 1.1.1

Author SHA1 Message Date
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
5 changed files with 81 additions and 17 deletions

View File

@@ -71,6 +71,19 @@ function items(items, channel) {
let fullContent = '<header>' + img + ' <h1>' + item.title + '</h1>' + menu + '</header>' + item.content;
if (item.goals.length > 0) {
item.goals.forEach(goal => item_values.push({
"turbo:goal": {
_attr: {
type: goal.type || 'yandex',
'turbo-goal-id': goal.id,
name: goal.name,
id: goal.counter_id,
}
}
}))
}
item_values.push({'turbo:content': {_cdata: fullContent}});
if (typeof item.related !== 'undefined') {
@@ -111,6 +124,27 @@ function generateXML(data) {
};
}
/**
* @param data
* @returns {*}
*/
function itemData(data) {
return {
title: data.title || '',
description: data.description || '',
image_url: data.image_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 || [],
};
}
/**
* Base function
* @param options
@@ -129,22 +163,7 @@ function TR(options, items) {
this.item = function (data) {
data = data || {};
let item = {
title: data.title || '',
description: data.description || '',
image_url: data.image_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 || ''
};
this.items.push(item);
this.items.push(itemData(data));
return this;
};

View File

@@ -1,6 +1,6 @@
{
"name": "turbo-rss",
"version": "1.0.8",
"version": "1.1.0",
"description": "RSS based, feed generator for Yandex turbo",
"keywords": [
"yandex",

View File

@@ -45,6 +45,7 @@ feed.item(itemOptions);
* `relatedfinity` _optional_ **bool** Непрерывная лента статей
* `turboSource` _optional_ **string** URL страницы-источника, который можно передать в Яндекс.Метрику.
* `turboTopic` _optional_ **string** Заголовок страницы, который можно передать в Яндекс.Метрику.
* `goals` _optional_ **array** массив типа: { _id_ - внутренний идентификатор цели (turbo-goal-id), _name_ - имя цели, _counter_id_ - id счётчика яндекс-метрики }
###### menu array
menu должен содержать массив объектов со следующими опциями:
@@ -84,6 +85,12 @@ 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: 'Главная'

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

@@ -132,3 +132,40 @@ test('menu', function (t) {
t.equal(feed.xml(), expectedOutput.menu.trim());
});
test('goals', function (t) {
t.plan(1);
let feed = new TR({
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: '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: [{
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.goal.trim());
});