mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 03:56:19 +00:00
Added turbo:goal support
This commit is contained in:
16
lib/index.js
16
lib/index.js
@@ -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') {
|
||||
@@ -128,7 +141,8 @@ function itemData(data) {
|
||||
related: data.related,
|
||||
relatedfinity: data.relatedfinity || false,
|
||||
turboSource: data.turboSource || '',
|
||||
turboTopic: data.turboTopic || ''
|
||||
turboTopic: data.turboTopic || '',
|
||||
goals: data.goals || [],
|
||||
};
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -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: 'Главная'
|
||||
|
||||
1
test/expectedOutput/goal.xml
Normal file
1
test/expectedOutput/goal.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><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>
|
||||
@@ -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());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user