mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 12:06:20 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8645a88b01 | ||
|
|
c65b6ccc12 | ||
|
|
4b0f033aa9 | ||
|
|
86678c6448 | ||
|
|
83c8380108 | ||
|
|
c76f5a522f | ||
|
|
415afbc2e3 | ||
|
|
6819999a2e | ||
|
|
4ddd19e269 | ||
|
|
2a4e3c5083 | ||
|
|
b7f6667798 | ||
|
|
e1516f9e1b | ||
|
|
44d345ac6b |
5
.codeclimate.yml
Normal file
5
.codeclimate.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
plugins:
|
||||||
|
eslint:
|
||||||
|
enabled: true
|
||||||
|
config:
|
||||||
|
config: .eslintrc.json
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
# Get the plugin for your editor and your
|
|
||||||
# tab settings will be set automatically.
|
|
||||||
# http://EditorConfig.org
|
|
||||||
|
|
||||||
# top-most EditorConfig file
|
|
||||||
root = true
|
|
||||||
|
|
||||||
# Unix-style newlines with no newline ending every file
|
|
||||||
[*]
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = false
|
|
||||||
|
|
||||||
# Indentation override for all JS under lib directory
|
|
||||||
[*.js]
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 4
|
|
||||||
28
.eslintrc.json
Normal file
28
.eslintrc.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"env": {
|
||||||
|
"es6": true,
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": "eslint:recommended",
|
||||||
|
"parserOptions": {
|
||||||
|
"sourceType": "module"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"indent": [
|
||||||
|
"error",
|
||||||
|
4
|
||||||
|
],
|
||||||
|
"linebreak-style": [
|
||||||
|
"error",
|
||||||
|
"unix"
|
||||||
|
],
|
||||||
|
"quotes": [
|
||||||
|
"error",
|
||||||
|
"single"
|
||||||
|
],
|
||||||
|
"semi": [
|
||||||
|
"error",
|
||||||
|
"always"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
*.log
|
*.log
|
||||||
|
coverage/
|
||||||
14
.jshintrc
14
.jshintrc
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"esversion":6,
|
|
||||||
"curly": true,
|
|
||||||
"eqeqeq": true,
|
|
||||||
"immed": true,
|
|
||||||
"latedef": true,
|
|
||||||
"newcap": true,
|
|
||||||
"noarg": true,
|
|
||||||
"sub": true,
|
|
||||||
"undef": true,
|
|
||||||
"boss": true,
|
|
||||||
"eqnull": true,
|
|
||||||
"node": true
|
|
||||||
}
|
|
||||||
18
.travis.yml
18
.travis.yml
@@ -1,11 +1,21 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
sudo: false
|
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:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- node_js: '0.10'
|
- node_js: '8.11.2'
|
||||||
before_install: npm -g i npm@2
|
before_install: npm -g i npm@2
|
||||||
- node_js: '0.12'
|
- node_js: '6.11.2'
|
||||||
before_install: npm -g i npm@2
|
before_install: npm -g i npm@2
|
||||||
- node_js: '4'
|
- node_js: '10.2.1'
|
||||||
before_install: npm -g i npm@2
|
before_install: npm -g i npm@2
|
||||||
|
|
||||||
|
|||||||
51
Gruntfile.js
51
Gruntfile.js
@@ -1,51 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
module.exports = function(grunt) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* grunt release or grunt release:patch increment the patch number
|
|
||||||
* grunt release:minor increments the minor version number
|
|
||||||
* grunt release:major increments the major version number
|
|
||||||
*
|
|
||||||
|
|
||||||
* grunt readme to generate the readme (you might need to do grunt repos first)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
require('time-grunt')(grunt);
|
|
||||||
|
|
||||||
grunt.initConfig({
|
|
||||||
jshint: {
|
|
||||||
options: {
|
|
||||||
jshintrc: '.jshintrc'
|
|
||||||
},
|
|
||||||
all: [
|
|
||||||
'Gruntfile.js',
|
|
||||||
'lib/**/*.js',
|
|
||||||
'test/**/*.js'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
release: {
|
|
||||||
github: {
|
|
||||||
repo: 'dylang/node-rss',
|
|
||||||
accessTokenVar: 'GITHUB_ACCESS_TOKEN'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
require('load-grunt-tasks')(grunt);
|
|
||||||
|
|
||||||
grunt.registerTask('lint', [
|
|
||||||
'jshint'
|
|
||||||
]);
|
|
||||||
|
|
||||||
grunt.registerTask('default', [
|
|
||||||
'lint'
|
|
||||||
]);
|
|
||||||
|
|
||||||
grunt.registerTask('pre-publish', [
|
|
||||||
'lint',
|
|
||||||
'repos',
|
|
||||||
'readme'
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
109
lib/index.js
109
lib/index.js
@@ -2,31 +2,57 @@
|
|||||||
|
|
||||||
const xml = require('xml');
|
const xml = require('xml');
|
||||||
|
|
||||||
function ifTruePush(bool, array, data) {
|
/**
|
||||||
if (bool) {
|
* Check first argument. If true - push last argument to second argument
|
||||||
|
* @param condition
|
||||||
|
* @param array
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
function ifTruePush(condition, array, data) {
|
||||||
|
if (condition) {
|
||||||
array.push(data);
|
array.push(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateXML(data) {
|
/**
|
||||||
|
* @param related
|
||||||
|
* @param itemValues
|
||||||
|
* @param relatedfinity
|
||||||
|
*/
|
||||||
|
function addRelated(related, itemValues, relatedfinity) {
|
||||||
|
let relatedResult = related.map(function (rel) {
|
||||||
|
return {
|
||||||
|
link: [{
|
||||||
|
_attr: {
|
||||||
|
'url': rel.link,
|
||||||
|
'img': rel.image_url
|
||||||
|
}
|
||||||
|
}, rel.text]
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
let channel = [];
|
if (relatedfinity) {
|
||||||
|
relatedResult.push({
|
||||||
|
_attr: {'type': 'infinity'}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
channel.push({title: {_cdata: data.title}});
|
ifTruePush(related, itemValues, {'yandex:related': relatedResult});
|
||||||
channel.push({link: data.link || 'http://github.com/LightAir/turbo-rss'});
|
}
|
||||||
channel.push({description: {_cdata: data.description || data.title}});
|
|
||||||
channel.push({language: 'ru'});
|
|
||||||
|
|
||||||
data.items.forEach(function (item) {
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Items processing
|
||||||
|
* @param items
|
||||||
|
* @param channel
|
||||||
|
*/
|
||||||
|
function items(items, channel) {
|
||||||
|
items.forEach(function (item) {
|
||||||
let item_values = [];
|
let item_values = [];
|
||||||
|
|
||||||
item_values.push({_attr: {'turbo': 'true'}});
|
item_values.push({_attr: {'turbo': 'true'}});
|
||||||
|
|
||||||
item_values.push({link: item.url});
|
item_values.push({link: item.url});
|
||||||
item_values.push({'turbo:source': item.url});
|
item_values.push({'turbo:source': item.url});
|
||||||
|
|
||||||
ifTruePush(item.date, item_values, {pubDate: new Date(item.date).toGMTString()});
|
ifTruePush(item.date, item_values, {pubDate: new Date(item.date).toUTCString()});
|
||||||
ifTruePush(item.author, item_values, {author: item.author});
|
ifTruePush(item.author, item_values, {author: item.author});
|
||||||
|
|
||||||
let img = '';
|
let img = '';
|
||||||
@@ -44,18 +70,28 @@ function generateXML(data) {
|
|||||||
|
|
||||||
item_values.push({'turbo:content': {_cdata: fullContent}});
|
item_values.push({'turbo:content': {_cdata: fullContent}});
|
||||||
|
|
||||||
if (typeof item.related !== "undefined") {
|
if (typeof item.related !== 'undefined') {
|
||||||
ifTruePush(item.related, item_values, {
|
addRelated(item.related, item_values, item.relatedfinity);
|
||||||
'yandex:related': item.related.map(
|
|
||||||
function (related) {
|
|
||||||
return '<link url="' + related.link + '" img="' + related.image_url + '">' + related.text + '</link>';
|
|
||||||
}
|
|
||||||
).join('')
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
channel.push({item: item_values});
|
|
||||||
|
|
||||||
|
channel.push({item: item_values});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data
|
||||||
|
* @returns {{rss: *[]}}
|
||||||
|
*/
|
||||||
|
function generateXML(data) {
|
||||||
|
|
||||||
|
let channel = [];
|
||||||
|
|
||||||
|
channel.push({title: {_cdata: data.title}});
|
||||||
|
channel.push({link: data.link || 'http://github.com/LightAir/turbo-rss'});
|
||||||
|
channel.push({description: {_cdata: data.description || data.title}});
|
||||||
|
channel.push({language: 'ru'});
|
||||||
|
|
||||||
|
items(data.items, channel);
|
||||||
|
|
||||||
let _attr = {
|
let _attr = {
|
||||||
'xmlns:yandex': 'http://news.yandex.ru',
|
'xmlns:yandex': 'http://news.yandex.ru',
|
||||||
@@ -72,6 +108,12 @@ function generateXML(data) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base function
|
||||||
|
* @param options
|
||||||
|
* @param items
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
function YTurbo(options, items) {
|
function YTurbo(options, items) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
@@ -80,18 +122,19 @@ function YTurbo(options, items) {
|
|||||||
this.link = options.link;
|
this.link = options.link;
|
||||||
this.items = items || [];
|
this.items = items || [];
|
||||||
|
|
||||||
this.item = function (options) {
|
this.item = function (data) {
|
||||||
options = options || {};
|
data = data || {};
|
||||||
let item = {
|
let item = {
|
||||||
title: options.title || 'No title',
|
title: data.title || 'No title',
|
||||||
description: options.description || '',
|
description: data.description || '',
|
||||||
image_url: options.image_url,
|
image_url: data.image_url,
|
||||||
url: options.url,
|
url: data.url,
|
||||||
author: options.author,
|
author: data.author,
|
||||||
date: options.date || options.pubDate,
|
date: data.date || data.pubDate,
|
||||||
content: options.content,
|
content: data.content,
|
||||||
menu: options.menu,
|
menu: data.menu,
|
||||||
related: options.related
|
related: data.related,
|
||||||
|
relatedfinity: data.relatedfinity || false,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.items.push(item);
|
this.items.push(item);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "turbo-rss",
|
"name": "turbo-rss",
|
||||||
"version": "1.0.5",
|
"version": "1.0.7",
|
||||||
"description": "RSS based, feed generator for Yandex turbo",
|
"description": "RSS based, feed generator for Yandex turbo",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"yandex",
|
"yandex",
|
||||||
@@ -11,8 +11,7 @@
|
|||||||
"main": "lib/index",
|
"main": "lib/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tape test --tap | tap-difflet",
|
"test": "tape test --tap | tap-difflet",
|
||||||
"lint": "grunt lint",
|
"coverage": "istanbul cover tape test -- -R spec"
|
||||||
"test:browser": "prova -b"
|
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/LightAir/turbo-rss",
|
"homepage": "https://github.com/LightAir/turbo-rss",
|
||||||
"author": {
|
"author": {
|
||||||
@@ -56,6 +55,7 @@
|
|||||||
"xml": "1.0.1"
|
"xml": "1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"eslint": "^4.19.1",
|
||||||
"folderify": "^1.1.0",
|
"folderify": "^1.1.0",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
"grunt-cli": "^0.1.13",
|
"grunt-cli": "^0.1.13",
|
||||||
|
|||||||
17
readme.md
17
readme.md
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
## turbo-rss
|
## 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://travis-ci.org/LightAir/turbo-rss)
|
||||||

|
[](https://www.npmjs.com/package/turbo-rss)
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
>Генератор RSS разметки для сервиса Турбо-страницы
|
>Генератор RSS разметки для сервиса Турбо-страницы
|
||||||
|
|
||||||
@@ -44,10 +45,18 @@ feed.item(itemOptions);
|
|||||||
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
||||||
* `date` **string** Время публикации контента на сайте источника.
|
* `date` **string** Время публикации контента на сайте источника.
|
||||||
* `content` **string** Содержимое страницы
|
* `content` **string** Содержимое страницы
|
||||||
* `related` _optional_ **object** Аффилированные ссылки `yandex:related` в конце статьи.
|
* `related` _optional_ **array** Аффилированные ссылки `yandex:related` в конце статьи.
|
||||||
|
* `relatedfinity` _optional_ **bool** Непрерывная лента статей
|
||||||
|
|
||||||
*Будет добавлено в новых версиях turbo:source, turbo:topic, menu, pubDate как алиас date*
|
*Будет добавлено в новых версиях turbo:source, turbo:topic, menu, pubDate как алиас date*
|
||||||
|
|
||||||
|
###### related array
|
||||||
|
related должен содержать массив объектов со следующими опциями:
|
||||||
|
|
||||||
|
* `link` **string** ссылка на статью'
|
||||||
|
* `image_url` **string** ссылка на изображение к статье
|
||||||
|
* `text` **string** текст ссылки
|
||||||
|
|
||||||
##### Получение XML
|
##### Получение XML
|
||||||
|
|
||||||
```js
|
```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 2012 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>
|
||||||
@@ -45,7 +45,8 @@ test('related item', function(t) {
|
|||||||
image_url: 'http://example.com/example.png',
|
image_url: 'http://example.com/example.png',
|
||||||
url: 'http://example.com/article4?this&that',
|
url: 'http://example.com/article4?this&that',
|
||||||
author: 'LightAir',
|
author: 'LightAir',
|
||||||
date: 'May 27, 2012',
|
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>',
|
content: '<p>hello</p>',
|
||||||
related: [{
|
related: [{
|
||||||
link: 'http://example.com/related/post1',
|
link: 'http://example.com/related/post1',
|
||||||
@@ -60,3 +61,34 @@ test('related item', function(t) {
|
|||||||
|
|
||||||
t.equal(feed.xml(), expectedOutput.relatedItem.trim());
|
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