mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 12:06:20 +00:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17030f0b82 | ||
|
|
e7d4333b45 | ||
|
|
5c8fbfaa40 | ||
|
|
ba8fe7ed26 | ||
|
|
83f2045b23 | ||
|
|
01aa654b03 | ||
|
|
c676a924b0 | ||
|
|
7aceeeaa36 | ||
|
|
9cccd65768 | ||
|
|
812a429d9b | ||
|
|
15c9715cee | ||
|
|
816b6b5690 | ||
|
|
ef90f974bd | ||
|
|
8aa086865d | ||
|
|
6d3cd71f47 | ||
|
|
ec44f8e5d3 | ||
|
|
7770e925fd | ||
|
|
9864d6408a | ||
|
|
3d5258a6c7 | ||
|
|
a8e4ba436c | ||
|
|
acd60d5922 | ||
| cfea55ea4c | |||
|
|
93815ec708 | ||
|
|
c5a7ff6e1c | ||
|
|
2d3f75902f |
@@ -23,6 +23,12 @@
|
|||||||
"semi": [
|
"semi": [
|
||||||
"error",
|
"error",
|
||||||
"always"
|
"always"
|
||||||
]
|
],
|
||||||
|
"no-var": "error",
|
||||||
|
"no-multi-spaces": "error",
|
||||||
|
"space-in-parens": "error",
|
||||||
|
"no-multiple-empty-lines": "error",
|
||||||
|
"prefer-const": "error",
|
||||||
|
"no-use-before-define": "error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,9 +13,4 @@ after_script:
|
|||||||
- codeclimate-test-reporter < ./coverage/lcov.info
|
- codeclimate-test-reporter < ./coverage/lcov.info
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- node_js: '8.11.2'
|
- node_js: 'lts/*'
|
||||||
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
|
|
||||||
|
|||||||
231
lib/index.js
231
lib/index.js
@@ -1,26 +1,58 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const xml = require('xml');
|
const baseXml = require('xml');
|
||||||
|
|
||||||
/**
|
class TR {
|
||||||
|
constructor(options, items) {
|
||||||
|
options = options || {};
|
||||||
|
|
||||||
|
this.title = options.title || '';
|
||||||
|
this.link = options.link || '';
|
||||||
|
this.description = options.description || '';
|
||||||
|
this.language = options.language || 'ru';
|
||||||
|
this.items = [];
|
||||||
|
|
||||||
|
if (Array.isArray(items) && items.length > 0) {
|
||||||
|
const self = this;
|
||||||
|
items.forEach(function (item) {
|
||||||
|
self.item(item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xml() {
|
||||||
|
return baseXml(this.generateXML(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
item(data) {
|
||||||
|
data = data || {};
|
||||||
|
this.items.push(
|
||||||
|
this.itemData(data)
|
||||||
|
);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Check first argument. If true - push last argument to second argument
|
* Check first argument. If true - push last argument to second argument
|
||||||
|
*
|
||||||
* @param condition
|
* @param condition
|
||||||
* @param array
|
* @param array
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
function ifTruePush(condition, array, data) {
|
pushIfConditionTrue(condition, array, data) {
|
||||||
if (condition) {
|
if (condition) {
|
||||||
array.push(data);
|
array.push(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param related
|
* @param related
|
||||||
* @param itemValues
|
* @param itemValues
|
||||||
* @param relatedfinity
|
* @param relatedInfinity
|
||||||
*/
|
*/
|
||||||
function addRelated(related, itemValues, relatedfinity) {
|
addRelated(related, itemValues, relatedInfinity) {
|
||||||
let relatedResult = related.map(function (rel) {
|
const relatedResult = related.map(function (rel) {
|
||||||
return {
|
return {
|
||||||
link: [{
|
link: [{
|
||||||
_attr: {
|
_attr: {
|
||||||
@@ -31,72 +63,126 @@ function addRelated(related, itemValues, relatedfinity) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (relatedfinity) {
|
if (relatedInfinity) {
|
||||||
relatedResult.push({
|
relatedResult.push({
|
||||||
_attr: {'type': 'infinity'}
|
_attr: {'type': 'infinity'}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ifTruePush(related, itemValues, {'yandex:related': relatedResult});
|
this.pushIfConditionTrue(related, itemValues, {'yandex:related': relatedResult});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param item
|
||||||
|
* @param itemValues
|
||||||
|
*/
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getImageContent(item) {
|
||||||
|
if (item.image_url.length > 0) {
|
||||||
|
let imageCaption = '';
|
||||||
|
|
||||||
|
if (item.image_caption.length > 0) {
|
||||||
|
imageCaption = `<figcaption>${item.image_caption}</figcaption>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `<figure><img src="${item.image_url}" />${imageCaption}</figure>`;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
getSubheading(item) {
|
||||||
|
if (item.subheading.length > 0) {
|
||||||
|
return `<h2>${item.subheading}</h2>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
getLinksString(links) {
|
||||||
|
return links.map(function (item) {
|
||||||
|
return `<a href="${item.link}">${item.text}</a>`;
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
getMenu(item) {
|
||||||
|
if (Array.isArray(item.menu) && item.menu.length > 0) {
|
||||||
|
return `<menu>${this.getLinksString(item.menu)}</menu>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
getBreadcrumbs(item) {
|
||||||
|
if (Array.isArray(item.breadcrumbs) && item.breadcrumbs.length > 0) {
|
||||||
|
return `<div data-block="breadcrumblist">${this.getLinksString(item.breadcrumbs)}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Items processing
|
* Items processing
|
||||||
* @param items
|
* @param items
|
||||||
* @param channel
|
* @param channel
|
||||||
*/
|
*/
|
||||||
function items(items, channel) {
|
itemsProcessing(items, channel) {
|
||||||
|
const self = this;
|
||||||
items.forEach(function (item) {
|
items.forEach(function (item) {
|
||||||
let item_values = [];
|
const itemValues = [];
|
||||||
item_values.push({_attr: {'turbo': 'true'}});
|
itemValues.push({_attr: {'turbo': item.turboEnabled ? 'true' : 'false'}});
|
||||||
item_values.push({link: item.url});
|
itemValues.push({link: item.url});
|
||||||
|
|
||||||
ifTruePush(item.turboSource, item_values, {'turbo:source': item.turboSource});
|
self.pushIfConditionTrue(item.extendedHtml, itemValues, {'turbo:extendedHtml': 'true'});
|
||||||
ifTruePush(item.turboTopic, item_values, {'turbo:topic': item.turboTopic});
|
self.pushIfConditionTrue(item.turboSource, itemValues, {'turbo:source': item.turboSource});
|
||||||
ifTruePush(item.date, item_values, {pubDate: new Date(item.date).toUTCString()});
|
self.pushIfConditionTrue(item.turboTopic, itemValues, {'turbo:topic': item.turboTopic});
|
||||||
ifTruePush(item.author, item_values, {author: item.author});
|
self.pushIfConditionTrue(item.date, itemValues, {pubDate: new Date(item.date).toUTCString()});
|
||||||
|
self.pushIfConditionTrue(item.author, itemValues, {author: item.author});
|
||||||
|
|
||||||
let img = '';
|
const fullContent = `<header>${self.getImageContent(item)}<h1>${item.title}</h1>${self.getSubheading(item)}${self.getMenu(item)}${self.getBreadcrumbs(item)}</header>${item.content}`;
|
||||||
let menu = '';
|
|
||||||
|
|
||||||
if (item.image_url) {
|
self.pushGoals(item, itemValues);
|
||||||
img = '<figure><img src="' + item.image_url + '" /></figure>';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(item.menu)) {
|
itemValues.push({'turbo:content': {_cdata: fullContent}});
|
||||||
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}});
|
|
||||||
|
|
||||||
if (typeof item.related !== 'undefined') {
|
if (typeof item.related !== 'undefined') {
|
||||||
addRelated(item.related, item_values, item.relatedfinity);
|
self.addRelated(item.related, itemValues, item.relatedInfinity);
|
||||||
}
|
}
|
||||||
|
|
||||||
channel.push({item: item_values});
|
channel.push({item: itemValues});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param data
|
* @param options
|
||||||
|
*
|
||||||
* @returns {{rss: *[]}}
|
* @returns {{rss: *[]}}
|
||||||
*/
|
*/
|
||||||
function generateXML(data) {
|
generateXML(options) {
|
||||||
|
|
||||||
let channel = [];
|
const channel = [];
|
||||||
|
|
||||||
channel.push({title: {_cdata: data.title}});
|
channel.push({title: {_cdata: options.title}});
|
||||||
channel.push({link: data.link});
|
channel.push({link: options.link});
|
||||||
channel.push({description: {_cdata: data.description || data.title}});
|
channel.push({description: {_cdata: options.description}});
|
||||||
channel.push({language: data.language});
|
channel.push({language: options.language});
|
||||||
|
|
||||||
items(data.items, channel);
|
this.itemsProcessing(options.items, channel);
|
||||||
|
|
||||||
let _attr = {
|
const _attr = {
|
||||||
'xmlns:yandex': 'http://news.yandex.ru',
|
'xmlns:yandex': 'http://news.yandex.ru',
|
||||||
'xmlns:media': 'http://search.yahoo.com/mrss/',
|
'xmlns:media': 'http://search.yahoo.com/mrss/',
|
||||||
'xmlns:turbo': 'http://turbo.yandex.ru',
|
'xmlns:turbo': 'http://turbo.yandex.ru',
|
||||||
@@ -109,48 +195,33 @@ function generateXML(data) {
|
|||||||
{channel: channel}
|
{channel: channel}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base function
|
* @param data
|
||||||
* @param options
|
* @returns {*}
|
||||||
* @param items
|
|
||||||
* @constructor
|
|
||||||
*/
|
*/
|
||||||
function TR(options, items) {
|
itemData(data) {
|
||||||
options = options || {};
|
return {
|
||||||
|
title: data.title || '', // h1
|
||||||
this.title = options.title || '';
|
subheading: data.subheading || '', // h2
|
||||||
this.link = options.link || '';
|
image_url: data.image_url || '',
|
||||||
this.description = options.description || '';
|
image_caption: data.image_caption || '',
|
||||||
this.language = options.language || 'ru';
|
|
||||||
|
|
||||||
this.items = 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,
|
url: data.url || data.link,
|
||||||
author: data.author,
|
author: data.author,
|
||||||
date: data.date || data.pubDate,
|
date: data.date || data.pubDate,
|
||||||
content: data.content,
|
content: data.content,
|
||||||
menu: data.menu,
|
menu: data.menu || [],
|
||||||
|
breadcrumbs: data.breadcrumbs || [],
|
||||||
related: data.related,
|
related: data.related,
|
||||||
relatedfinity: data.relatedfinity || false,
|
relatedInfinity: data.relatedInfinity || false,
|
||||||
turboSource: data.turboSource || '',
|
turboSource: data.turboSource || '',
|
||||||
turboTopic: data.turboTopic || ''
|
turboTopic: data.turboTopic || '',
|
||||||
};
|
goals: data.goals || [],
|
||||||
|
turboEnabled: data.turboEnabled !== undefined ? data.turboEnabled : true,
|
||||||
this.items.push(item);
|
extendedHtml: data.extendedHtml || false,
|
||||||
return this;
|
|
||||||
};
|
|
||||||
|
|
||||||
this.xml = function () {
|
|
||||||
return xml(generateXML(this));
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = TR;
|
module.exports = TR;
|
||||||
|
|||||||
29
package.json
29
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "turbo-rss",
|
"name": "turbo-rss",
|
||||||
"version": "1.0.8",
|
"version": "2.0.1",
|
||||||
"description": "RSS based, feed generator for Yandex turbo",
|
"description": "RSS based, feed generator for Yandex turbo",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"yandex",
|
"yandex",
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
],
|
],
|
||||||
"main": "lib/index",
|
"main": "lib/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tape test --tap | tap-difflet",
|
"test": "tape test --tap | tap-min",
|
||||||
"coverage": "istanbul cover tape test -- -R spec"
|
"coverage": "istanbul cover tape test -- -R spec"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/LightAir/turbo-rss",
|
"homepage": "https://github.com/LightAir/turbo-rss",
|
||||||
@@ -56,27 +56,12 @@
|
|||||||
"xml": "1.0.1"
|
"xml": "1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^4.19.1",
|
"eslint": "^7.28.0",
|
||||||
"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",
|
|
||||||
"include-folder": "^1.0.0",
|
"include-folder": "^1.0.0",
|
||||||
"load-grunt-tasks": "^3.3.0",
|
"mockdate": "^3.0.5",
|
||||||
"mockdate": "^1.0.3",
|
"q": "^1.5.1",
|
||||||
"prova": "^2.1.2",
|
"tap-min": "~2.0.0",
|
||||||
"q": "^1.4.1",
|
"tape": "^5.2.2"
|
||||||
"tap-difflet": "^0.4.0",
|
|
||||||
"tape": "^4.2.1",
|
|
||||||
"time-grunt": "^1.2.1",
|
|
||||||
"xml2js": "^0.4.12"
|
|
||||||
},
|
|
||||||
"browserify": {
|
|
||||||
"transform": [
|
|
||||||
"folderify"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
33
readme.md
33
readme.md
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
[](https://codeclimate.com/github/LightAir/turbo-rss/maintainability)
|
[](https://codeclimate.com/github/LightAir/turbo-rss/maintainability)
|
||||||
[](https://codeclimate.com/github/LightAir/turbo-rss/test_coverage)
|
[](https://codeclimate.com/github/LightAir/turbo-rss/test_coverage)
|
||||||
[](https://travis-ci.org/LightAir/turbo-rss)
|
[](https://app.travis-ci.com/LightAir/turbo-rss)
|
||||||
[](https://www.npmjs.com/package/turbo-rss)
|
[](https://www.npmjs.com/package/turbo-rss)
|
||||||

|

|
||||||
|
|
||||||
>Генератор RSS разметки для сервиса Турбо-страницы https://yandex.ru/support/webmaster/turbo/connection.html
|
>Генератор RSS разметки для сервиса Турбо-страницы https://yandex.ru/support/webmaster/turbo/connection.html
|
||||||
@@ -35,16 +35,21 @@ feed.item(itemOptions);
|
|||||||
##### itemOptions
|
##### itemOptions
|
||||||
|
|
||||||
* `title` **string** Заголовок страницы.
|
* `title` **string** Заголовок страницы.
|
||||||
|
* `subheading` _optional_ **string** Подзаголовок страницы.
|
||||||
* `image_url` _optional_ **url string** Адрес изображения, которое используется в качестве обложки. Изображение может быть в любом формате.
|
* `image_url` _optional_ **url string** Адрес изображения, которое используется в качестве обложки. Изображение может быть в любом формате.
|
||||||
|
* `image_caption` _optional_ **string** Подпись к изображению обложки.
|
||||||
* `link` **url string** URL страницы сайта, для которой нужно сформировать Турбо-страницу.
|
* `link` **url string** URL страницы сайта, для которой нужно сформировать Турбо-страницу.
|
||||||
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
||||||
* `date` или `pubDate` **string** Время публикации контента на сайте источника. Передается в формате RFC-822.
|
* `date` или `pubDate` **string** Время публикации контента на сайте источника. Передается в формате RFC-822.
|
||||||
* `content` **string** Содержимое страницы
|
* `content` **string** Содержимое страницы
|
||||||
* `menu` _optional_ **array** Внимание! Меню будет отображаться только в том случае, если в настройках на странице Яндекс Вебмастер -> Турбо-страницы -> Настройки, содержимое 'Меню Турбо-страниц' пустое!
|
* `menu` _optional_ **array** Внимание! Меню будет отображаться только в том случае, если в настройках на странице Яндекс Вебмастер -> Турбо-страницы -> Настройки, содержимое 'Меню Турбо-страниц' пустое!
|
||||||
|
* `breadcrumbs` _optional_ **array** Навигационная ссылка https://yandex.ru/dev/turbo/doc/rss/elements/header.html#breadcrumbs
|
||||||
* `related` _optional_ **array** Аффилированные ссылки `yandex:related` в конце статьи. Вы можете разместить ссылки на другие ресурсы или настроить отображение непрерывной ленты статей, реализованной, например с помощью AJAX.
|
* `related` _optional_ **array** Аффилированные ссылки `yandex:related` в конце статьи. Вы можете разместить ссылки на другие ресурсы или настроить отображение непрерывной ленты статей, реализованной, например с помощью AJAX.
|
||||||
* `relatedfinity` _optional_ **bool** Непрерывная лента статей
|
* `relatednfinity` _optional_ **bool** Непрерывная лента статей (Параметр был переименован из relatedfinity)
|
||||||
* `turboSource` _optional_ **string** URL страницы-источника, который можно передать в Яндекс.Метрику.
|
* `turboSource` _optional_ **string** URL страницы-источника, который можно передать в Яндекс.Метрику.
|
||||||
* `turboTopic` _optional_ **string** Заголовок страницы, который можно передать в Яндекс.Метрику.
|
* `turboTopic` _optional_ **string** Заголовок страницы, который можно передать в Яндекс.Метрику.
|
||||||
|
* `goals` _optional_ **array** массив типа: { _id_ - внутренний идентификатор цели (turbo-goal-id), _name_ - имя цели, _counter_id_ - id счётчика яндекс-метрики }
|
||||||
|
* `turboEnabled`_optional_ **bool** Принудительная установка атрибута "turbo". По умолчанию true. Установка в false позволит скрыть отображение турбо-страницы
|
||||||
|
|
||||||
###### menu array
|
###### menu array
|
||||||
menu должен содержать массив объектов со следующими опциями:
|
menu должен содержать массив объектов со следующими опциями:
|
||||||
@@ -52,6 +57,12 @@ feed.item(itemOptions);
|
|||||||
* `link` **url string** ссылка
|
* `link` **url string** ссылка
|
||||||
* `text` **string** текст ссылки. не должен содержать html
|
* `text` **string** текст ссылки. не должен содержать html
|
||||||
|
|
||||||
|
###### breadcrumbs array
|
||||||
|
Один элемент хлебных крошек должен содержать массив объектов со следующими опциями:
|
||||||
|
|
||||||
|
* `link` **url string** ссылка
|
||||||
|
* `text` **string** текст ссылки (не должен содержать html)
|
||||||
|
|
||||||
###### related array
|
###### related array
|
||||||
related должен содержать массив объектов со следующими опциями:
|
related должен содержать массив объектов со следующими опциями:
|
||||||
|
|
||||||
@@ -84,13 +95,19 @@ feed.item({
|
|||||||
author: 'LightAir',
|
author: 'LightAir',
|
||||||
date: 'May 27, 2012',
|
date: 'May 27, 2012',
|
||||||
content: '<p>hello</p>',
|
content: '<p>hello</p>',
|
||||||
|
goals: [{
|
||||||
|
type: "yandex",
|
||||||
|
id: "turbo-goal-id",
|
||||||
|
counter_id: "12345",
|
||||||
|
name: "order",
|
||||||
|
}],
|
||||||
menu: [{
|
menu: [{
|
||||||
link: 'http://example.com/',
|
link: 'http://example.com/',
|
||||||
text: 'Главная'
|
text: 'Главная'
|
||||||
}, {
|
}, {
|
||||||
link: 'http://example.com/about',
|
link: 'http://example.com/about',
|
||||||
text: 'О сайте'
|
text: 'О сайте'
|
||||||
}]
|
}],
|
||||||
related: [{
|
related: [{
|
||||||
link: 'http://example.com/related/post1',
|
link: 'http://example.com/related/post1',
|
||||||
image_url: 'http://example.com/i/img1.jpg',
|
image_url: 'http://example.com/i/img1.jpg',
|
||||||
@@ -112,3 +129,11 @@ var xml = feed.xml();
|
|||||||
```sh
|
```sh
|
||||||
$ npm test
|
$ npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Спасибо
|
||||||
|
|
||||||
|
@jahglow
|
||||||
|
|
||||||
|
@vvmspace
|
||||||
|
|
||||||
|
@crackosok
|
||||||
|
|||||||
1
test/expectedOutput/breadcrumbs.xml
Normal file
1
test/expectedOutput/breadcrumbs.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>https://example.com/soups/with-potatoes/</link><pubDate>Sat, 26 May 2018 21:00:00 GMT</pubDate><author>LightAir</author><turbo:content><![CDATA[<header><figure><img src="https://example.com/example.png" /></figure><h1>Суп с картофелем</h1><div data-block="breadcrumblist"><a href="https://example.com/">Главная</a><a href="https://example.com/soups/">Супы</a><a href="https://example.com/soups/with-potatoes/">Суп с картофелем</a></div></header><p>Для приготовления супа с картофелем, возьмите</p>]]></turbo:content></item></channel></rss>
|
||||||
@@ -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:content><![CDATA[<header> <h1></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>
|
||||||
|
|||||||
1
test/expectedOutput/defaultItemTurboFalse.xml
Normal file
1
test/expectedOutput/defaultItemTurboFalse.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="false"><link></link><turbo:content><![CDATA[<header><h1></h1></header>undefined]]></turbo:content></item></channel></rss>
|
||||||
@@ -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/><link></link><description/><language>ru</language><item turbo="true"><link></link><turbo:content><![CDATA[<header> <h1></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>
|
||||||
|
|||||||
1
test/expectedOutput/defaultTwoItem.xml
Normal file
1
test/expectedOutput/defaultTwoItem.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/><link></link><description/><language>ru</language><item turbo="true"><link></link><turbo:content><![CDATA[<header><h1></h1></header>undefined]]></turbo:content></item><item turbo="true"><link></link><turbo:content><![CDATA[<header><h1></h1></header>undefined]]></turbo:content></item></channel></rss>
|
||||||
1
test/expectedOutput/extendedHtml.xml
Normal file
1
test/expectedOutput/extendedHtml.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></link><turbo:extendedHtml>true</turbo:extendedHtml><turbo:content><![CDATA[<header><h1></h1></header>undefined]]></turbo:content></item></channel></rss>
|
||||||
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>
|
||||||
1
test/expectedOutput/imageCaption.xml
Normal file
1
test/expectedOutput/imageCaption.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>LightAir</author><turbo:content><![CDATA[<header><figure><img src="http://example.com/example.png" /><figcaption>this is image caption</figcaption></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>
|
||||||
@@ -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&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>
|
<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>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>
|
||||||
|
|||||||
@@ -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&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>
|
<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>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>
|
||||||
|
|||||||
@@ -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&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>
|
<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>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>
|
||||||
|
|||||||
1
test/expectedOutput/subheading.xml
Normal file
1
test/expectedOutput/subheading.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></link><turbo:content><![CDATA[<header><h1>item title</h1><h2>Subheading</h2></header>undefined]]></turbo:content></item></channel></rss>
|
||||||
207
test/index.js
207
test/index.js
@@ -1,30 +1,56 @@
|
|||||||
// prova is a wrapper for tape
|
|
||||||
// use npm run test:browser to run tests in a browser
|
|
||||||
const test = require('tape');
|
const test = require('tape');
|
||||||
|
|
||||||
const TR = require('..');
|
const TR = require('..');
|
||||||
|
|
||||||
const includeFolder = require('include-folder');
|
const includeFolder = require('include-folder');
|
||||||
const expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
|
const expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
|
||||||
|
|
||||||
require('mockdate').set('Wed, 10 Dec 2014 19:04:57 GMT');
|
const baseOptions = {
|
||||||
|
|
||||||
test('empty feed', function (t) {
|
|
||||||
t.plan(2);
|
|
||||||
let feed = new TR();
|
|
||||||
t.equal(feed.xml(), expectedOutput.default.trim());
|
|
||||||
feed.item();
|
|
||||||
t.equal(feed.xml(), expectedOutput.defaultOneItem.trim());
|
|
||||||
});
|
|
||||||
|
|
||||||
test('default item', function (t) {
|
|
||||||
t.plan(1);
|
|
||||||
let feed = new TR({
|
|
||||||
title: 'title',
|
title: 'title',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
link: 'http://example.com/rss.xml',
|
link: 'http://example.com/rss.xml',
|
||||||
site_url: 'http://example.com'
|
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(3);
|
||||||
|
|
||||||
|
const feed = new TR();
|
||||||
|
t.equal(feed.xml(), expectedOutput.default.trim());
|
||||||
|
|
||||||
|
feed.item();
|
||||||
|
t.equal(feed.xml(), expectedOutput.defaultOneItem.trim());
|
||||||
|
|
||||||
|
feed.item();
|
||||||
|
t.equal(feed.xml(), expectedOutput.defaultTwoItem.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('empty feed constructor', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
const feed = new TR(
|
||||||
|
{},
|
||||||
|
[{}, {}]
|
||||||
|
);
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.defaultTwoItem.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('default item', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
const feed = new TR(baseOptions);
|
||||||
|
|
||||||
feed.item({});
|
feed.item({});
|
||||||
|
|
||||||
@@ -33,12 +59,7 @@ test('default item', function (t) {
|
|||||||
|
|
||||||
test('related item', function (t) {
|
test('related item', function (t) {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
let feed = new TR({
|
const feed = new TR(baseOptions);
|
||||||
title: 'title',
|
|
||||||
description: 'description',
|
|
||||||
link: 'http://example.com/rss.xml',
|
|
||||||
site_url: 'http://example.com'
|
|
||||||
});
|
|
||||||
|
|
||||||
feed.item({
|
feed.item({
|
||||||
title: 'item title',
|
title: 'item title',
|
||||||
@@ -48,15 +69,7 @@ test('related item', function (t) {
|
|||||||
date: 'May 27, 2018 00:00 AM',
|
date: 'May 27, 2018 00:00 AM',
|
||||||
menu: '<a href="http://example.com/page1.html">Текст ссылки</a> <a href="http://example.com/page2.html">Текст ссылки</a>',
|
menu: '<a href="http://example.com/page1.html">Текст ссылки</a> <a href="http://example.com/page2.html">Текст ссылки</a>',
|
||||||
content: '<p>hello</p>',
|
content: '<p>hello</p>',
|
||||||
related: [{
|
related: 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'
|
|
||||||
}]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
t.equal(feed.xml(), expectedOutput.relatedItem.trim());
|
t.equal(feed.xml(), expectedOutput.relatedItem.trim());
|
||||||
@@ -64,12 +77,7 @@ test('related item', function (t) {
|
|||||||
|
|
||||||
test('related item', function (t) {
|
test('related item', function (t) {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
let feed = new TR({
|
const feed = new TR(baseOptions);
|
||||||
title: 'title',
|
|
||||||
description: 'description',
|
|
||||||
link: 'http://example.com/rss.xml',
|
|
||||||
site_url: 'http://example.com'
|
|
||||||
});
|
|
||||||
|
|
||||||
feed.item({
|
feed.item({
|
||||||
title: 'item title',
|
title: 'item title',
|
||||||
@@ -78,16 +86,8 @@ test('related item', function (t) {
|
|||||||
author: 'LightAir',
|
author: 'LightAir',
|
||||||
date: 'May 27, 2018 00:00 AM',
|
date: 'May 27, 2018 00:00 AM',
|
||||||
content: '<p>hello</p>',
|
content: '<p>hello</p>',
|
||||||
relatedfinity: true,
|
relatedInfinity: true,
|
||||||
related: [{
|
related: 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'
|
|
||||||
}]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
t.equal(feed.xml(), expectedOutput.relatedItemInfinity.trim());
|
t.equal(feed.xml(), expectedOutput.relatedItemInfinity.trim());
|
||||||
@@ -95,12 +95,7 @@ test('related item', function (t) {
|
|||||||
|
|
||||||
test('menu', function (t) {
|
test('menu', function (t) {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
let feed = new TR({
|
const feed = new TR(baseOptions);
|
||||||
title: 'title',
|
|
||||||
description: 'description',
|
|
||||||
link: 'http://example.com/rss.xml',
|
|
||||||
site_url: 'http://example.com'
|
|
||||||
});
|
|
||||||
|
|
||||||
feed.item({
|
feed.item({
|
||||||
title: 'item title',
|
title: 'item title',
|
||||||
@@ -109,7 +104,7 @@ test('menu', function (t) {
|
|||||||
author: 'LightAir',
|
author: 'LightAir',
|
||||||
date: 'May 27, 2018 00:00 AM',
|
date: 'May 27, 2018 00:00 AM',
|
||||||
content: '<p>hello</p>',
|
content: '<p>hello</p>',
|
||||||
relatedfinity: true,
|
relatedInfinity: true,
|
||||||
menu: [{
|
menu: [{
|
||||||
link: 'http://example.com/',
|
link: 'http://example.com/',
|
||||||
text: 'Главная',
|
text: 'Главная',
|
||||||
@@ -117,18 +112,102 @@ test('menu', function (t) {
|
|||||||
link: 'http://example.com/about',
|
link: 'http://example.com/about',
|
||||||
text: 'О сайте',
|
text: 'О сайте',
|
||||||
}],
|
}],
|
||||||
related: [{
|
related: 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'
|
|
||||||
}]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
feed.item({});
|
feed.item({});
|
||||||
|
|
||||||
t.equal(feed.xml(), expectedOutput.menu.trim());
|
t.equal(feed.xml(), expectedOutput.menu.trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('goals', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
const 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());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('image caption', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
const feed = new TR(baseOptions);
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
title: 'item title',
|
||||||
|
image_url: 'http://example.com/example.png',
|
||||||
|
image_caption: 'this is image caption',
|
||||||
|
url: 'http://example.com/article4?this&that',
|
||||||
|
author: 'LightAir',
|
||||||
|
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: relatedOptions
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.imageCaption.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('subheading', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
const feed = new TR(baseOptions);
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
title: 'item title',
|
||||||
|
subheading: 'Subheading',
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.subheading.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('breadcrumbs', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
const feed = new TR(baseOptions);
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
title: 'Суп с картофелем',
|
||||||
|
image_url: 'https://example.com/example.png',
|
||||||
|
breadcrumbs: [{
|
||||||
|
link: 'https://example.com/',
|
||||||
|
text: 'Главная',
|
||||||
|
}, {
|
||||||
|
link: 'https://example.com/soups/',
|
||||||
|
text: 'Супы',
|
||||||
|
}, {
|
||||||
|
link: 'https://example.com/soups/with-potatoes/',
|
||||||
|
text: 'Суп с картофелем'
|
||||||
|
}],
|
||||||
|
url: 'https://example.com/soups/with-potatoes/',
|
||||||
|
author: 'LightAir',
|
||||||
|
date: 'May 27, 2018 00:00 AM',
|
||||||
|
content: '<p>Для приготовления супа с картофелем, возьмите</p>'
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.breadcrumbs.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('item extendedHtml', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
const feed = new TR(baseOptions);
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
extendedHtml: true
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.extendedHtml.trim());
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user