From c5a7ff6e1c9638f1762c024fedf236349055e4ec Mon Sep 17 00:00:00 2001 From: vvm Date: Mon, 31 Aug 2020 23:08:53 +0300 Subject: [PATCH] Added turbo:goal support --- lib/index.js | 16 +++++++++++++++- readme.md | 7 +++++++ test/expectedOutput/goal.xml | 1 + test/index.js | 37 ++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/expectedOutput/goal.xml diff --git a/lib/index.js b/lib/index.js index c4d8221..4b25c58 100755 --- a/lib/index.js +++ b/lib/index.js @@ -71,6 +71,19 @@ function items(items, channel) { let fullContent = '
' + img + '

' + item.title + '

' + menu + '
' + 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 || [], }; } /** diff --git a/readme.md b/readme.md index a139187..aa79ded 100644 --- a/readme.md +++ b/readme.md @@ -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: '

hello

', + goals: [{ + type: "yandex", + id: "turbo-goal-id", + counter_id: "12345", + name: "order", + }], menu: [{ link: 'http://example.com/', text: 'Главная' diff --git a/test/expectedOutput/goal.xml b/test/expectedOutput/goal.xml new file mode 100644 index 0000000..fe5a1c1 --- /dev/null +++ b/test/expectedOutput/goal.xml @@ -0,0 +1 @@ +<![CDATA[title]]>http://example.com/rss.xmlruhttp://example.com/article4?this&thatSat, 26 May 2018 21:00:00 GMTvvm.space

item title

hello

]]>
related link text 1related link text 2
diff --git a/test/index.js b/test/index.js index 22456f9..b74c4dd 100644 --- a/test/index.js +++ b/test/index.js @@ -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: 'Текст ссылки Текст ссылки', + goals: [{ + type: "yandex", + id: "turbo-goal-id", + counter_id: "12345", + name: "order", + }], + content: '

hello

', + 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()); +});