9 Commits
1.0.5 ... 1.0.6

Author SHA1 Message Date
la
83c8380108 add new version 2018-05-30 12:18:15 +03:00
la
c76f5a522f cleaning repo 2018-05-30 12:17:22 +03:00
la
415afbc2e3 add bages 2018-05-30 11:29:09 +03:00
la
6819999a2e Code climate 2018-05-30 11:12:37 +03:00
la
4ddd19e269 Проблема с времнем 2018-05-29 15:54:25 +03:00
la
2a4e3c5083 Изменены версии nodejs для travis 2018-05-29 14:35:32 +03:00
la
b7f6667798 Изменён способ добавления аттрибутов на правильный 2018-05-29 14:24:33 +03:00
la
e1516f9e1b update readme 2018-05-29 13:19:09 +03:00
la
44d345ac6b add eslint 2018-05-29 13:13:54 +03:00
10 changed files with 113 additions and 125 deletions

View File

@@ -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
View 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"
]
}
}

View File

@@ -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
}

View File

@@ -1,11 +1,13 @@
language: node_js
sudo: false
before_script:
- export TZ=Europe/Moscow
- date
matrix:
include:
- node_js: '0.10'
- node_js: '8.11.2'
before_install: npm -g i npm@2
- node_js: '0.12'
- node_js: '6.11.2'
before_install: npm -g i npm@2
- node_js: '4'
- node_js: '10.2.1'
before_install: npm -g i npm@2

View File

@@ -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'
]);
};

View File

@@ -2,31 +2,52 @@
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);
}
}
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'});
data.items.forEach(function (item) {
/**
* @param related
* @param itemValues
*/
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]
};
}
)
});
}
/**
* Items processing
* @param items
* @param channel
*/
function items(items, channel) {
items.forEach(function (item) {
let item_values = [];
item_values.push({_attr: {'turbo': 'true'}});
item_values.push({link: 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});
let img = '';
@@ -44,18 +65,28 @@ function generateXML(data) {
item_values.push({'turbo:content': {_cdata: fullContent}});
if (typeof item.related !== "undefined") {
ifTruePush(item.related, item_values, {
'yandex:related': item.related.map(
function (related) {
return '<link url="' + related.link + '" img="' + related.image_url + '">' + related.text + '</link>';
}
).join('')
});
if (typeof item.related !== 'undefined') {
addRelated(item.related, item_values);
}
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 = {
'xmlns:yandex': 'http://news.yandex.ru',
@@ -72,6 +103,12 @@ function generateXML(data) {
};
}
/**
* Base function
* @param options
* @param items
* @constructor
*/
function YTurbo(options, items) {
options = options || {};
@@ -80,18 +117,18 @@ function YTurbo(options, items) {
this.link = options.link;
this.items = items || [];
this.item = function (options) {
options = options || {};
this.item = function (data) {
data = data || {};
let item = {
title: options.title || 'No title',
description: options.description || '',
image_url: options.image_url,
url: options.url,
author: options.author,
date: options.date || options.pubDate,
content: options.content,
menu: options.menu,
related: options.related
title: data.title || 'No title',
description: data.description || '',
image_url: data.image_url,
url: data.url,
author: data.author,
date: data.date || data.pubDate,
content: data.content,
menu: data.menu,
related: data.related
};
this.items.push(item);

View File

@@ -1,6 +1,6 @@
{
"name": "turbo-rss",
"version": "1.0.5",
"version": "1.0.6",
"description": "RSS based, feed generator for Yandex turbo",
"keywords": [
"yandex",
@@ -56,6 +56,7 @@
"xml": "1.0.1"
},
"devDependencies": {
"eslint": "^4.19.1",
"folderify": "^1.1.0",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",

View File

@@ -2,9 +2,10 @@
## turbo-rss
[![Maintainability](https://api.codeclimate.com/v1/badges/6525d2aabf20185b68b6/maintainability)](https://codeclimate.com/github/LightAir/turbo-rss/maintainability)
[![Build Status](https://travis-ci.org/LightAir/turbo-rss.svg)](https://travis-ci.org/LightAir/turbo-rss)
![npm](https://img.shields.io/npm/v/npm.svg)
![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg)
[![npm](https://img.shields.io/badge/npm%20package-1.0.5-blue.svg?longCache=true&style=flat)](https://www.npmjs.com/package/turbo-rss)
![license](https://img.shields.io/packagist/l/doctrine/orm.svg?longCache=true&style=flat)
>Генератор RSS разметки для сервиса Турбо-страницы

View File

@@ -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&amp;that</link><turbo:source>http://example.com/article4?this&amp;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>&lt;link url=&quot;http://example.com/related/post1&quot; img=&quot;http://example.com/i/img1.jpg&quot;&gt;related link text 1&lt;/link&gt;&lt;link url=&quot;http://example.com/related/post2&quot; img=&quot;http://example.com/i/img2.jpg&quot;&gt;related link text 2&lt;/link&gt;</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&amp;that</link><turbo:source>http://example.com/article4?this&amp;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>

View File

@@ -45,7 +45,7 @@ test('related item', function(t) {
image_url: 'http://example.com/example.png',
url: 'http://example.com/article4?this&that',
author: 'LightAir',
date: 'May 27, 2012',
date: 'May 27, 2018 00:00 AM',
content: '<p>hello</p>',
related: [{
link: 'http://example.com/related/post1',