mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 12:06:20 +00:00
rss to yandex turbo
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
|
/.idea/
|
||||||
node_modules
|
node_modules
|
||||||
|
|||||||
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="JSHint" enabled="true" level="ERROR" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
85
.idea/jsLinters/jshint.xml
generated
Normal file
85
.idea/jsLinters/jshint.xml
generated
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JSHintConfiguration" version="2.9.5" use-config-file="true">
|
||||||
|
<option asi="false" />
|
||||||
|
<option bitwise="true" />
|
||||||
|
<option boss="false" />
|
||||||
|
<option browser="true" />
|
||||||
|
<option browserify="false" />
|
||||||
|
<option camelcase="false" />
|
||||||
|
<option couch="false" />
|
||||||
|
<option curly="true" />
|
||||||
|
<option debug="false" />
|
||||||
|
<option devel="false" />
|
||||||
|
<option dojo="false" />
|
||||||
|
<option elision="false" />
|
||||||
|
<option enforceall="false" />
|
||||||
|
<option eqeqeq="true" />
|
||||||
|
<option eqnull="false" />
|
||||||
|
<option es3="false" />
|
||||||
|
<option es5="false" />
|
||||||
|
<option esnext="false" />
|
||||||
|
<option evil="false" />
|
||||||
|
<option expr="false" />
|
||||||
|
<option forin="true" />
|
||||||
|
<option freeze="false" />
|
||||||
|
<option funcscope="false" />
|
||||||
|
<option futurehostile="false" />
|
||||||
|
<option gcl="false" />
|
||||||
|
<option globalstrict="false" />
|
||||||
|
<option immed="false" />
|
||||||
|
<option iterator="false" />
|
||||||
|
<option jasmine="false" />
|
||||||
|
<option jquery="false" />
|
||||||
|
<option lastsemic="false" />
|
||||||
|
<option latedef="false" />
|
||||||
|
<option laxbreak="false" />
|
||||||
|
<option laxcomma="false" />
|
||||||
|
<option loopfunc="false" />
|
||||||
|
<option maxerr="50" />
|
||||||
|
<option mocha="false" />
|
||||||
|
<option module="false" />
|
||||||
|
<option mootools="false" />
|
||||||
|
<option moz="false" />
|
||||||
|
<option multistr="false" />
|
||||||
|
<option newcap="false" />
|
||||||
|
<option noarg="true" />
|
||||||
|
<option nocomma="false" />
|
||||||
|
<option node="false" />
|
||||||
|
<option noempty="true" />
|
||||||
|
<option nomen="false" />
|
||||||
|
<option nonbsp="false" />
|
||||||
|
<option nonew="true" />
|
||||||
|
<option nonstandard="false" />
|
||||||
|
<option notypeof="false" />
|
||||||
|
<option noyield="false" />
|
||||||
|
<option onevar="false" />
|
||||||
|
<option passfail="false" />
|
||||||
|
<option phantom="false" />
|
||||||
|
<option plusplus="false" />
|
||||||
|
<option proto="false" />
|
||||||
|
<option prototypejs="false" />
|
||||||
|
<option qunit="false" />
|
||||||
|
<option quotmark="false" />
|
||||||
|
<option rhino="false" />
|
||||||
|
<option scripturl="false" />
|
||||||
|
<option shadow="false" />
|
||||||
|
<option shelljs="false" />
|
||||||
|
<option singleGroups="false" />
|
||||||
|
<option smarttabs="false" />
|
||||||
|
<option strict="true" />
|
||||||
|
<option sub="false" />
|
||||||
|
<option supernew="false" />
|
||||||
|
<option trailing="false" />
|
||||||
|
<option typed="false" />
|
||||||
|
<option undef="true" />
|
||||||
|
<option unused="false" />
|
||||||
|
<option validthis="false" />
|
||||||
|
<option varstmt="false" />
|
||||||
|
<option white="false" />
|
||||||
|
<option withstmt="false" />
|
||||||
|
<option worker="false" />
|
||||||
|
<option wsh="false" />
|
||||||
|
<option yui="false" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"esversion":6,
|
||||||
"curly": true,
|
"curly": true,
|
||||||
"eqeqeq": true,
|
"eqeqeq": true,
|
||||||
"immed": true,
|
"immed": true,
|
||||||
|
|||||||
193
lib/index.js
193
lib/index.js
@@ -1,9 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var mime = require('mime-types');
|
const xml = require('xml');
|
||||||
var xml = require('xml');
|
|
||||||
var fs = require('fs');
|
|
||||||
|
|
||||||
|
|
||||||
function ifTruePush(bool, array, data) {
|
function ifTruePush(bool, array, data) {
|
||||||
if (bool) {
|
if (bool) {
|
||||||
@@ -11,179 +8,91 @@ function ifTruePush(bool, array, data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ifTruePushArray(bool, array, dataArray) {
|
function generateXML(data) {
|
||||||
if(!bool) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dataArray.forEach(function(item) {
|
let channel = [];
|
||||||
ifTruePush(item, array, item);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSize(filename) {
|
channel.push({title: {_cdata: data.title}});
|
||||||
if (typeof fs === 'undefined') {
|
channel.push({link: data.link || 'http://github.com/lightair/yandex-turbo'});
|
||||||
return 0;
|
channel.push({description: {_cdata: data.description || data.title}});
|
||||||
}
|
channel.push({language: 'ru'});
|
||||||
return fs.statSync(filename).size;
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateXML (data){
|
data.items.forEach(function (item) {
|
||||||
|
|
||||||
var channel = [];
|
let item_values = [];
|
||||||
channel.push({ title: { _cdata: data.title } });
|
|
||||||
channel.push({ description: { _cdata: data.description || data.title } });
|
|
||||||
channel.push({ link: data.site_url || 'http://github.com/dylang/node-rss' });
|
|
||||||
// image_url set?
|
|
||||||
if (data.image_url) {
|
|
||||||
channel.push({ image: [ {url: data.image_url}, {title: data.title}, {link: data.site_url} ] });
|
|
||||||
}
|
|
||||||
channel.push({ generator: data.generator });
|
|
||||||
channel.push({ lastBuildDate: new Date().toUTCString() });
|
|
||||||
|
|
||||||
ifTruePush(data.feed_url, channel, { 'atom:link': { _attr: { href: data.feed_url, rel: 'self', type: 'application/rss+xml' } } });
|
item_values.push({_attr: {'turbo': 'true'}});
|
||||||
ifTruePush(data.author, channel, { 'author': { _cdata: data.author } });
|
|
||||||
ifTruePush(data.pubDate, channel, { 'pubDate': new Date(data.pubDate).toGMTString() });
|
|
||||||
ifTruePush(data.copyright, channel, { 'copyright': { _cdata: data.copyright } });
|
|
||||||
ifTruePush(data.language, channel, { 'language': { _cdata: data.language } });
|
|
||||||
ifTruePush(data.managingEditor, channel, { 'managingEditor': { _cdata: data.managingEditor } });
|
|
||||||
ifTruePush(data.webMaster, channel, { 'webMaster': { _cdata: data.webMaster } });
|
|
||||||
ifTruePush(data.docs, channel, { 'docs': data.docs });
|
|
||||||
ifTruePush(data.ttl, channel, { 'ttl': data.ttl });
|
|
||||||
ifTruePush(data.hub, channel, { 'atom:link': { _attr: { href: data.hub, rel: 'hub' } } });
|
|
||||||
|
|
||||||
if (data.categories) {
|
item_values.push({link: item.url});
|
||||||
data.categories.forEach(function(category) {
|
item_values.push({'turbo:source': item.url});
|
||||||
ifTruePush(category, channel, { category: { _cdata: category } });
|
// item_values.push({'turbo:topic': item.title});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ifTruePushArray(data.custom_elements, channel, data.custom_elements);
|
ifTruePush(item.date, item_values, {pubDate: new Date(item.date).toGMTString()});
|
||||||
|
ifTruePush(item.author, item_values, {author: item.author});
|
||||||
|
|
||||||
data.items.forEach(function(item) {
|
let img = '';
|
||||||
var item_values = [
|
let menu = '';
|
||||||
{ title: { _cdata: item.title } }
|
|
||||||
];
|
|
||||||
ifTruePush(item.description, item_values, { description: { _cdata: item.description } });
|
|
||||||
ifTruePush(item.url, item_values, { link: item.url });
|
|
||||||
ifTruePush(item.link || item.guid || item.title, item_values, { guid: [ { _attr: { isPermaLink: !item.guid && !!item.url } }, item.guid || item.url || item.title ] });
|
|
||||||
|
|
||||||
item.categories.forEach(function(category) {
|
if (item.img) {
|
||||||
ifTruePush(category, item_values, { category: { _cdata: category } });
|
img = '<figure><img src="' + item.image_url + '" /></figure>';
|
||||||
});
|
|
||||||
|
|
||||||
ifTruePush(item.author || data.author, item_values, { 'dc:creator': { _cdata: item.author || data.author } });
|
|
||||||
ifTruePush(item.date, item_values, { pubDate: new Date(item.date).toGMTString() });
|
|
||||||
|
|
||||||
//Set GeoRSS to true if lat and long are set
|
|
||||||
data.geoRSS = data.geoRSS || (item.lat && item.long);
|
|
||||||
ifTruePush(item.lat, item_values, {'geo:lat': item.lat});
|
|
||||||
ifTruePush(item.long, item_values, {'geo:long': item.long});
|
|
||||||
|
|
||||||
if( item.enclosure && item.enclosure.url) {
|
|
||||||
if( item.enclosure.file ) {
|
|
||||||
item_values.push({
|
|
||||||
enclosure : {
|
|
||||||
_attr : {
|
|
||||||
url : item.enclosure.url,
|
|
||||||
length : item.enclosure.size || getSize(item.enclosure.file),
|
|
||||||
type : item.enclosure.type || mime.lookup(item.enclosure.file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
item_values.push({
|
|
||||||
enclosure : {
|
|
||||||
_attr : {
|
|
||||||
url : item.enclosure.url,
|
|
||||||
length : item.enclosure.size || 0,
|
|
||||||
type : item.enclosure.type || mime.lookup(item.enclosure.url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ifTruePushArray(item.custom_elements, item_values, item.custom_elements);
|
if (item.menu) {
|
||||||
|
menu = '<menu>' + item.menu + '</menu>';
|
||||||
|
}
|
||||||
|
|
||||||
channel.push({ item: item_values });
|
let fullContent = '<header>' + img + ' <h1>' + item.title + '</h1>' + item.content + menu + '</header>';
|
||||||
|
|
||||||
|
item_values.push({'turbo:content': {_cdata: fullContent}});
|
||||||
|
channel.push({item: item_values});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//set up the attributes for the RSS feed.
|
let _attr = {
|
||||||
var _attr = {
|
'xmlns:yandex': 'http://news.yandex.ru',
|
||||||
'xmlns:dc': 'http://purl.org/dc/elements/1.1/',
|
'xmlns:media': 'http://search.yahoo.com/mrss/',
|
||||||
'xmlns:content': 'http://purl.org/rss/1.0/modules/content/',
|
'xmlns:turbo': 'http://turbo.yandex.ru',
|
||||||
'xmlns:atom': 'http://www.w3.org/2005/Atom',
|
|
||||||
version: '2.0'
|
version: '2.0'
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.keys(data.custom_namespaces).forEach(function(name) {
|
|
||||||
_attr['xmlns:' + name] = data.custom_namespaces[name];
|
|
||||||
});
|
|
||||||
|
|
||||||
//only add namespace if GeoRSS is true
|
|
||||||
if(data.geoRSS){
|
|
||||||
_attr['xmlns:geo'] = 'http://www.w3.org/2003/01/geo/wgs84_pos#';
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
rss: [
|
rss: [
|
||||||
{ _attr: _attr },
|
{_attr: _attr},
|
||||||
{ channel: channel }
|
{channel: channel}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function RSS (options, items) {
|
function YTurbo(options, items) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
this.title = options.title || 'Untitled RSS Feed';
|
this.title = options.title || 'Channel Yandex RSS';
|
||||||
this.description = options.description || '';
|
this.description = options.description || '';
|
||||||
this.generator = options.generator || 'RSS for Node';
|
this.link = options.link;
|
||||||
this.feed_url = options.feed_url;
|
this.image_url = options.image_url;
|
||||||
this.site_url = options.site_url;
|
this.author = options.author;
|
||||||
this.image_url = options.image_url;
|
this.content = options.content;
|
||||||
this.author = options.author;
|
this.pubDate = options.pubDate;
|
||||||
this.categories = options.categories;
|
this.items = items || [];
|
||||||
this.pubDate = options.pubDate;
|
|
||||||
this.hub = options.hub;
|
|
||||||
this.docs = options.docs;
|
|
||||||
this.copyright = options.copyright;
|
|
||||||
this.language = options.language;
|
|
||||||
this.managingEditor = options.managingEditor;
|
|
||||||
this.webMaster = options.webMaster;
|
|
||||||
this.ttl = options.ttl;
|
|
||||||
//option to return feed as GeoRSS is set automatically if feed.lat/long is used
|
|
||||||
this.geoRSS = options.geoRSS || false;
|
|
||||||
this.custom_namespaces = options.custom_namespaces || {};
|
|
||||||
this.custom_elements = options.custom_elements || [];
|
|
||||||
this.items = items || [];
|
|
||||||
|
|
||||||
this.item = function (options) {
|
this.item = function (options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
var item = {
|
let item = {
|
||||||
title: options.title || 'No title',
|
title: options.title || 'No title',
|
||||||
description: options.description || '',
|
description: options.description || '',
|
||||||
url: options.url,
|
url: options.url,
|
||||||
guid: options.guid,
|
author: options.author,
|
||||||
categories: options.categories || [],
|
date: options.date,
|
||||||
author: options.author,
|
content: options.content
|
||||||
date: options.date,
|
|
||||||
lat: options.lat,
|
|
||||||
long: options.long,
|
|
||||||
enclosure: options.enclosure || false,
|
|
||||||
custom_elements: options.custom_elements || []
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this.items.push(item);
|
this.items.push(item);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.xml = function(indent) {
|
this.xml = function (indent) {
|
||||||
return '<?xml version="1.0" encoding="UTF-8"?>' +
|
return xml(generateXML(this), indent);
|
||||||
xml(generateXML(this), indent);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RSS;
|
module.exports = YTurbo;
|
||||||
|
|||||||
5569
package-lock.json
generated
Normal file
5569
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@@ -1,16 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "rss",
|
"name": "turbo-rss",
|
||||||
"version": "1.2.2",
|
"version": "1.0.0",
|
||||||
"description": "RSS feed generator. Add RSS feeds to any project. Supports enclosures and GeoRSS.",
|
"description": "RSS based, feed generator for Yandex turbo",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"rss",
|
"yandex",
|
||||||
"xml",
|
"turbo",
|
||||||
"atom",
|
"rss yandex",
|
||||||
"podcasts",
|
"yandex turbo"
|
||||||
"ghost",
|
|
||||||
"feed",
|
|
||||||
"feed builder",
|
|
||||||
"rss feed"
|
|
||||||
],
|
],
|
||||||
"main": "lib/index",
|
"main": "lib/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -18,12 +14,13 @@
|
|||||||
"lint": "grunt lint",
|
"lint": "grunt lint",
|
||||||
"test:browser": "prova -b"
|
"test:browser": "prova -b"
|
||||||
},
|
},
|
||||||
"homepage": "http://github.com/dylang/node-rss",
|
"homepage": "http://github.com/lightair/yandex-turbo",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Dylan Greene",
|
"name": "LightAir",
|
||||||
"email": "dylang@gmail.com"
|
"email": "public@softroot.ru"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
"LightAir <public@softroot.ru>",
|
||||||
"Dylan Greene <dylang@gmail.com>",
|
"Dylan Greene <dylang@gmail.com>",
|
||||||
"Xavier Damman <xdamman@gmail.com>",
|
"Xavier Damman <xdamman@gmail.com>",
|
||||||
"Michael R. Lange",
|
"Michael R. Lange",
|
||||||
@@ -37,10 +34,10 @@
|
|||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://github.com/dylang/node-rss.git"
|
"url": "http://github.com/lightair/yandex-turbo.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "http://github.com/dylang/node-rss/issues"
|
"url": "http://github.com/lightair/yandex-turbo/issues"
|
||||||
},
|
},
|
||||||
"testling": {
|
"testling": {
|
||||||
"files": "test/*.js",
|
"files": "test/*.js",
|
||||||
@@ -56,7 +53,6 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mime-types": "2.1.13",
|
|
||||||
"xml": "1.0.1"
|
"xml": "1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
18
readme.md
18
readme.md
@@ -1,12 +1,6 @@
|
|||||||
## rss [](https://travis-ci.org/dylang/node-rss) [](https://www.npmjs.org/package/rss)
|
## turbo-rss [](https://travis-ci.org/lightair/turbo-rss)
|
||||||
|
|
||||||
> RSS feed generator. Add RSS feeds to any project. Supports enclosures and GeoRSS.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
>RSS based, feed generator for Yandex turbo.
|
||||||
|
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
@@ -14,18 +8,16 @@
|
|||||||
#### Create a new feed
|
#### Create a new feed
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var RSS = require('rss');
|
var TS = require('turbo-rss');
|
||||||
|
|
||||||
var feed = new RSS(feedOptions);
|
var feed = new TS(feedOptions);
|
||||||
```
|
```
|
||||||
|
|
||||||
##### `feedOptions`
|
##### `feedOptions`
|
||||||
|
|
||||||
* `title` **string** Title of your site or feed
|
* `title` **string** Title of your site or feed
|
||||||
* `description` _optional_ **string** A short description of the feed.
|
* `description` _optional_ **string** A short description of the feed.
|
||||||
* `generator` _optional_ **string** Feed generator.
|
* `link` **url string** Url to the site that the feed is for.
|
||||||
* `feed_url` **url string** Url to the rss feed.
|
|
||||||
* `site_url` **url string** Url to the site that the feed is for.
|
|
||||||
* `image_url` _optional_ **url string** Small image for feed readers to use.
|
* `image_url` _optional_ **url string** Small image for feed readers to use.
|
||||||
* `docs` _optional_ **url string** Url to documentation on this feed.
|
* `docs` _optional_ **url string** Url to documentation on this feed.
|
||||||
* `managingEditor` _optional_ **string** Who manages content in this feed.
|
* `managingEditor` _optional_ **string** Who manages content in this feed.
|
||||||
|
|||||||
Reference in New Issue
Block a user