mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 12:06:20 +00:00
Рабочая версия
This commit is contained in:
29
lib/index.js
29
lib/index.js
@@ -50,8 +50,9 @@ function items(items, channel) {
|
||||
let item_values = [];
|
||||
item_values.push({_attr: {'turbo': 'true'}});
|
||||
item_values.push({link: item.url});
|
||||
item_values.push({'turbo:source': 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});
|
||||
|
||||
@@ -62,8 +63,10 @@ function items(items, channel) {
|
||||
img = '<figure><img src="' + item.image_url + '" /></figure>';
|
||||
}
|
||||
|
||||
if (item.menu) {
|
||||
menu = '<menu>' + item.menu + '</menu>';
|
||||
if (Array.isArray(item.menu)) {
|
||||
menu = '<menu>' + item.menu.map(function (item) {
|
||||
return '<a href="' + item.link + '">' + item.text + '</a>';
|
||||
}).join('') + '</menu>';
|
||||
}
|
||||
|
||||
let fullContent = '<header>' + img + ' <h1>' + item.title + '</h1>' + menu + '</header>' + item.content;
|
||||
@@ -87,9 +90,9 @@ function generateXML(data) {
|
||||
let channel = [];
|
||||
|
||||
channel.push({title: {_cdata: data.title}});
|
||||
channel.push({link: data.link || 'http://github.com/LightAir/turbo-rss'});
|
||||
channel.push({link: data.link});
|
||||
channel.push({description: {_cdata: data.description || data.title}});
|
||||
channel.push({language: 'ru'});
|
||||
channel.push({language: data.language});
|
||||
|
||||
items(data.items, channel);
|
||||
|
||||
@@ -114,27 +117,31 @@ function generateXML(data) {
|
||||
* @param items
|
||||
* @constructor
|
||||
*/
|
||||
function YTurbo(options, items) {
|
||||
function TR(options, items) {
|
||||
options = options || {};
|
||||
|
||||
this.title = options.title || 'Untitled';
|
||||
this.title = options.title || '';
|
||||
this.link = options.link || '';
|
||||
this.description = options.description || '';
|
||||
this.link = options.link;
|
||||
this.language = options.language || 'ru';
|
||||
|
||||
this.items = items || [];
|
||||
|
||||
this.item = function (data) {
|
||||
data = data || {};
|
||||
let item = {
|
||||
title: data.title || 'No title',
|
||||
title: data.title || '',
|
||||
description: data.description || '',
|
||||
image_url: data.image_url,
|
||||
url: data.url,
|
||||
url: data.url || data.link,
|
||||
author: data.author,
|
||||
date: data.date || data.pubDate,
|
||||
content: data.content,
|
||||
menu: data.menu,
|
||||
related: data.related,
|
||||
relatedfinity: data.relatedfinity || false,
|
||||
turboSource: data.turboSource || '',
|
||||
turboTopic: data.turboTopic || ''
|
||||
};
|
||||
|
||||
this.items.push(item);
|
||||
@@ -146,4 +153,4 @@ function YTurbo(options, items) {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = YTurbo;
|
||||
module.exports = TR;
|
||||
|
||||
Reference in New Issue
Block a user