mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 20:16:19 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8645a88b01 | ||
|
|
c65b6ccc12 | ||
|
|
4b0f033aa9 | ||
|
|
86678c6448 |
5
.codeclimate.yml
Normal file
5
.codeclimate.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
plugins:
|
||||
eslint:
|
||||
enabled: true
|
||||
config:
|
||||
config: .eslintrc.json
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
node_modules
|
||||
package-lock.json
|
||||
*.log
|
||||
coverage/
|
||||
@@ -1,8 +1,16 @@
|
||||
language: node_js
|
||||
sudo: false
|
||||
addons:
|
||||
code_climate:
|
||||
repo_token:
|
||||
secure: "Lz3KeRxbJ877gDe0kWNdAg3erDe4TVruP98Xes18N13H8XGyIdWs2GnJiRHHS831tCd3yYu5F643xNXJuQ3omWikvRVr0lu57yBdJVg0dhJwjEnP85DRIU3YmGAe4Ua5qNoMlhZMyZwL6TTHWt30SZ2NK/HmYOr+fI0/H8OTWtrxcMlwYYZkbmhllGAYWnXnZCOCHuIcio7L21pEX/PXtrQMTVNFuebT2Q8GihjoW00KeH8z4t7E+a7MFb427dX7MRYGHHGuu2dAUoDI/P5tz7FIQg83Uz4Jmnzh34Wc9uYLd5lTcRc6Mb7mOVHXO9ZLoVtxE7gB+apN+NkzhPhZjQToyvypwyzUZiHV9xtYj9abUuU5vXEdGTA4+KEy7iM25r7U1cqsVVWsXBckpEpprlvJ2FQbbajP9PZpvnSwFmbPDGFJf2uPs07xtav1F6fpAU9zSg8J+iagS9grmCccNcs4TrExWRCFLRupN2AC9SeLWCb2ux+3IMuqwNkJiiWYNzLMOHru2kxFGgc7+wd3bzREbgZJbYUHCmVchHVcUT2/dn240mSVnLoemP1z91VdxbUN3EwR0Hcp5LnTMqCSQ880QUmFjDFnd0huKXKrKrr61na/wVoUDrcQGg/DKgvGcDm6CqzeHfSM9EHqwbbYx4cZn36ZA1nDiNTMLSxHhn0="
|
||||
script: npm run coverage
|
||||
before_script:
|
||||
- export TZ=Europe/Moscow
|
||||
- date
|
||||
- npm install codeclimate-test-reporter istanbul -g
|
||||
after_script:
|
||||
- codeclimate-test-reporter < ./coverage/lcov.info
|
||||
matrix:
|
||||
include:
|
||||
- node_js: '8.11.2'
|
||||
|
||||
38
lib/index.js
38
lib/index.js
@@ -17,22 +17,27 @@ function ifTruePush(condition, array, data) {
|
||||
/**
|
||||
* @param related
|
||||
* @param itemValues
|
||||
* @param relatedfinity
|
||||
*/
|
||||
function addRelated(related, itemValues) {
|
||||
ifTruePush(related, itemValues, {
|
||||
'yandex:related': related.map(
|
||||
function (rel) {
|
||||
return {
|
||||
link: [{
|
||||
_attr: {
|
||||
'url': rel.link,
|
||||
'img': rel.image_url
|
||||
}
|
||||
}, rel.text]
|
||||
};
|
||||
}
|
||||
)
|
||||
function addRelated(related, itemValues, relatedfinity) {
|
||||
let relatedResult = related.map(function (rel) {
|
||||
return {
|
||||
link: [{
|
||||
_attr: {
|
||||
'url': rel.link,
|
||||
'img': rel.image_url
|
||||
}
|
||||
}, rel.text]
|
||||
};
|
||||
});
|
||||
|
||||
if (relatedfinity) {
|
||||
relatedResult.push({
|
||||
_attr: {'type': 'infinity'}
|
||||
});
|
||||
}
|
||||
|
||||
ifTruePush(related, itemValues, {'yandex:related': relatedResult});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,7 +71,7 @@ function items(items, channel) {
|
||||
item_values.push({'turbo:content': {_cdata: fullContent}});
|
||||
|
||||
if (typeof item.related !== 'undefined') {
|
||||
addRelated(item.related, item_values);
|
||||
addRelated(item.related, item_values, item.relatedfinity);
|
||||
}
|
||||
|
||||
channel.push({item: item_values});
|
||||
@@ -128,7 +133,8 @@ function YTurbo(options, items) {
|
||||
date: data.date || data.pubDate,
|
||||
content: data.content,
|
||||
menu: data.menu,
|
||||
related: data.related
|
||||
related: data.related,
|
||||
relatedfinity: data.relatedfinity || false,
|
||||
};
|
||||
|
||||
this.items.push(item);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "turbo-rss",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.7",
|
||||
"description": "RSS based, feed generator for Yandex turbo",
|
||||
"keywords": [
|
||||
"yandex",
|
||||
@@ -11,8 +11,7 @@
|
||||
"main": "lib/index",
|
||||
"scripts": {
|
||||
"test": "tape test --tap | tap-difflet",
|
||||
"lint": "grunt lint",
|
||||
"test:browser": "prova -b"
|
||||
"coverage": "istanbul cover tape test -- -R spec"
|
||||
},
|
||||
"homepage": "https://github.com/LightAir/turbo-rss",
|
||||
"author": {
|
||||
|
||||
14
readme.md
14
readme.md
@@ -3,11 +3,11 @@
|
||||
## turbo-rss
|
||||
|
||||
[](https://codeclimate.com/github/LightAir/turbo-rss/maintainability)
|
||||
[](https://codeclimate.com/github/LightAir/turbo-rss/test_coverage)
|
||||
[](https://travis-ci.org/LightAir/turbo-rss)
|
||||
[](https://www.npmjs.com/package/turbo-rss)
|
||||
[](https://www.npmjs.com/package/turbo-rss)
|
||||

|
||||
|
||||
|
||||
>Генератор RSS разметки для сервиса Турбо-страницы
|
||||
|
||||
>ПРЕДУПРЕЖДЕНИЕ! Работа в процессе
|
||||
@@ -45,10 +45,18 @@ feed.item(itemOptions);
|
||||
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
||||
* `date` **string** Время публикации контента на сайте источника.
|
||||
* `content` **string** Содержимое страницы
|
||||
* `related` _optional_ **object** Аффилированные ссылки `yandex:related` в конце статьи.
|
||||
* `related` _optional_ **array** Аффилированные ссылки `yandex:related` в конце статьи.
|
||||
* `relatedfinity` _optional_ **bool** Непрерывная лента статей
|
||||
|
||||
*Будет добавлено в новых версиях turbo:source, turbo:topic, menu, pubDate как алиас date*
|
||||
|
||||
###### related array
|
||||
related должен содержать массив объектов со следующими опциями:
|
||||
|
||||
* `link` **string** ссылка на статью'
|
||||
* `image_url` **string** ссылка на изображение к статье
|
||||
* `text` **string** текст ссылки
|
||||
|
||||
##### Получение XML
|
||||
|
||||
```js
|
||||
|
||||
@@ -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><turbo:source>http://example.com/article4?this&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><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><turbo:source>http://example.com/article4?this&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>
|
||||
|
||||
1
test/expectedOutput/relatedItemInfinity.xml
Normal file
1
test/expectedOutput/relatedItemInfinity.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><turbo:source>http://example.com/article4?this&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>
|
||||
@@ -46,6 +46,7 @@ test('related item', function(t) {
|
||||
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: [{
|
||||
link: 'http://example.com/related/post1',
|
||||
@@ -60,3 +61,34 @@ test('related item', function(t) {
|
||||
|
||||
t.equal(feed.xml(), expectedOutput.relatedItem.trim());
|
||||
});
|
||||
|
||||
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'
|
||||
});
|
||||
|
||||
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,
|
||||
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.relatedItemInfinity.trim());
|
||||
});
|
||||
Reference in New Issue
Block a user