Небольшие изменения

This commit is contained in:
LightAir
2020-12-02 00:32:13 +03:00
parent 7770e925fd
commit ec44f8e5d3
2 changed files with 37 additions and 45 deletions

View File

@@ -13,20 +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'
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/*' - 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'

View File

@@ -4,11 +4,12 @@ const xml = require('xml');
/** /**
* 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) { function pushIfConditionTrue(condition, array, data) {
if (condition) { if (condition) {
array.push(data); array.push(data);
} }
@@ -17,9 +18,9 @@ function ifTruePush(condition, array, data) {
/** /**
* @param related * @param related
* @param itemValues * @param itemValues
* @param relatedfinity * @param relatedInfinity
*/ */
function addRelated(related, itemValues, relatedfinity) { function addRelated(related, itemValues, relatedInfinity) {
let relatedResult = related.map(function (rel) { let relatedResult = related.map(function (rel) {
return { return {
link: [{ link: [{
@@ -31,13 +32,32 @@ 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}); 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) { function items(items, channel) {
items.forEach(function (item) { items.forEach(function (item) {
let item_values = []; let itemValues = [];
item_values.push({_attr: {'turbo': item.turboEnabled ? 'true' : 'false'}}); 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}); pushIfConditionTrue(item.turboSource, itemValues, {'turbo:source': item.turboSource});
ifTruePush(item.turboTopic, item_values, {'turbo:topic': item.turboTopic}); pushIfConditionTrue(item.turboTopic, itemValues, {'turbo:topic': item.turboTopic});
ifTruePush(item.date, item_values, {pubDate: new Date(item.date).toUTCString()}); pushIfConditionTrue(item.date, itemValues, {pubDate: new Date(item.date).toUTCString()});
ifTruePush(item.author, item_values, {author: item.author}); pushIfConditionTrue(item.author, itemValues, {author: item.author});
let img = ''; let img = '', menu = '';
let menu = '';
if (item.image_url) { if (item.image_url) {
img = '<figure><img src="' + item.image_url + '" /></figure>'; 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; let fullContent = '<header>' + img + ' <h1>' + item.title + '</h1>' + menu + '</header>' + item.content;
if (item.goals.length > 0) { pushGoals(item, itemValues);
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}}); itemValues.push({'turbo:content': {_cdata: fullContent}});
if (typeof item.related !== 'undefined') { 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});
}); });
} }