mirror of
https://github.com/LightAir/turbo-rss.git
synced 2025-12-17 14:27:53 +00:00
Небольшие изменения
This commit is contained in:
parent
7770e925fd
commit
ec44f8e5d3
16
.travis.yml
16
.travis.yml
@ -13,20 +13,4 @@ after_script:
|
||||
- codeclimate-test-reporter < ./coverage/lcov.info
|
||||
matrix:
|
||||
include:
|
||||
- node_js: '8.11.2'
|
||||
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
|
||||
- node_js: 'lts/*'
|
||||
before_install: npm -g i npm@2
|
||||
- node_js: '11'
|
||||
before_install: npm -g i npm@2
|
||||
- node_js: '12'
|
||||
before_install: npm -g i npm@2
|
||||
- node_js: '13'
|
||||
before_install: npm -g i npm@2
|
||||
- node_js: '14'
|
||||
before_install: npm -g i npm@2
|
||||
- node_js: '15'
|
||||
|
||||
66
lib/index.js
66
lib/index.js
@ -4,11 +4,12 @@ const xml = require('xml');
|
||||
|
||||
/**
|
||||
* Check first argument. If true - push last argument to second argument
|
||||
*
|
||||
* @param condition
|
||||
* @param array
|
||||
* @param data
|
||||
*/
|
||||
function ifTruePush(condition, array, data) {
|
||||
function pushIfConditionTrue(condition, array, data) {
|
||||
if (condition) {
|
||||
array.push(data);
|
||||
}
|
||||
@ -17,9 +18,9 @@ function ifTruePush(condition, array, data) {
|
||||
/**
|
||||
* @param related
|
||||
* @param itemValues
|
||||
* @param relatedfinity
|
||||
* @param relatedInfinity
|
||||
*/
|
||||
function addRelated(related, itemValues, relatedfinity) {
|
||||
function addRelated(related, itemValues, relatedInfinity) {
|
||||
let relatedResult = related.map(function (rel) {
|
||||
return {
|
||||
link: [{
|
||||
@ -31,13 +32,32 @@ function addRelated(related, itemValues, relatedfinity) {
|
||||
};
|
||||
});
|
||||
|
||||
if (relatedfinity) {
|
||||
if (relatedInfinity) {
|
||||
relatedResult.push({
|
||||
_attr: {'type': 'infinity'}
|
||||
});
|
||||
}
|
||||
|
||||
ifTruePush(related, itemValues, {'yandex:related': relatedResult});
|
||||
pushIfConditionTrue(related, itemValues, {'yandex:related': relatedResult});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* @param itemValues
|
||||
*/
|
||||
function 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,
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,17 +67,16 @@ function addRelated(related, itemValues, relatedfinity) {
|
||||
*/
|
||||
function items(items, channel) {
|
||||
items.forEach(function (item) {
|
||||
let item_values = [];
|
||||
item_values.push({_attr: {'turbo': item.turboEnabled ? 'true' : 'false'}});
|
||||
item_values.push({link: item.url});
|
||||
let itemValues = [];
|
||||
itemValues.push({_attr: {'turbo': item.turboEnabled ? 'true' : 'false'}});
|
||||
itemValues.push({link: item.url});
|
||||
|
||||
ifTruePush(item.turboSource, item_values, {'turbo:source': item.turboSource});
|
||||
ifTruePush(item.turboTopic, item_values, {'turbo:topic': item.turboTopic});
|
||||
ifTruePush(item.date, item_values, {pubDate: new Date(item.date).toUTCString()});
|
||||
ifTruePush(item.author, item_values, {author: item.author});
|
||||
pushIfConditionTrue(item.turboSource, itemValues, {'turbo:source': item.turboSource});
|
||||
pushIfConditionTrue(item.turboTopic, itemValues, {'turbo:topic': item.turboTopic});
|
||||
pushIfConditionTrue(item.date, itemValues, {pubDate: new Date(item.date).toUTCString()});
|
||||
pushIfConditionTrue(item.author, itemValues, {author: item.author});
|
||||
|
||||
let img = '';
|
||||
let menu = '';
|
||||
let img = '', menu = '';
|
||||
|
||||
if (item.image_url) {
|
||||
img = '<figure><img src="' + item.image_url + '" /></figure>';
|
||||
@ -71,26 +90,15 @@ 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,
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
pushGoals(item, itemValues);
|
||||
|
||||
item_values.push({'turbo:content': {_cdata: fullContent}});
|
||||
itemValues.push({'turbo:content': {_cdata: fullContent}});
|
||||
|
||||
if (typeof item.related !== 'undefined') {
|
||||
addRelated(item.related, item_values, item.relatedfinity);
|
||||
addRelated(item.related, itemValues, item.relatedfinity);
|
||||
}
|
||||
|
||||
channel.push({item: item_values});
|
||||
channel.push({item: itemValues});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user