mirror of
https://github.com/LightAir/turbo-rss.git
synced 2026-02-04 20:16:19 +00:00
Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec44f8e5d3 | ||
|
|
7770e925fd | ||
|
|
9864d6408a | ||
|
|
3d5258a6c7 | ||
|
|
a8e4ba436c | ||
|
|
acd60d5922 | ||
| cfea55ea4c | |||
|
|
93815ec708 | ||
|
|
c5a7ff6e1c | ||
|
|
2d3f75902f | ||
|
|
d896040f63 | ||
|
|
8645a88b01 | ||
|
|
c65b6ccc12 | ||
|
|
4b0f033aa9 | ||
|
|
86678c6448 | ||
|
|
83c8380108 | ||
|
|
c76f5a522f | ||
|
|
415afbc2e3 | ||
|
|
6819999a2e | ||
|
|
4ddd19e269 | ||
|
|
2a4e3c5083 | ||
|
|
b7f6667798 | ||
|
|
e1516f9e1b | ||
|
|
44d345ac6b | ||
|
|
c5a9e4b5fd | ||
|
|
97e23fe031 | ||
|
|
a4b18cde97 | ||
|
|
1dca86ab85 | ||
|
|
8b4ec85bcf | ||
|
|
b02eaab7e6 | ||
|
|
10e74b0a1b | ||
|
|
c47a6d3d0f | ||
|
|
365abd5592 | ||
|
|
8bd429accc | ||
|
|
43dadcd891 | ||
|
|
e4b5093678 | ||
|
|
28030cd0dc |
5
.codeclimate.yml
Normal file
5
.codeclimate.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
plugins:
|
||||||
|
eslint:
|
||||||
|
enabled: true
|
||||||
|
config:
|
||||||
|
config: .eslintrc.json
|
||||||
@@ -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
28
.eslintrc.json
Normal 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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
*.log
|
*.log
|
||||||
|
coverage/
|
||||||
14
.jshintrc
14
.jshintrc
@@ -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
|
|
||||||
}
|
|
||||||
19
.travis.yml
19
.travis.yml
@@ -1,11 +1,16 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
sudo: false
|
sudo: false
|
||||||
|
addons:
|
||||||
|
code_climate:
|
||||||
|
repo_token:
|
||||||
|
secure: "Lz3KeRxbJ877gDe0kWNdAg3erDe4TVruP98Xes18N13H8XGyIdWs2GnJiRHHS831tCd3yYu5F643xNXJuQ3omWikvRVr0lu57yBdJVg0dhJwjEnP85DRIU3YmGAe4Ua5qNoMlhZMyZwL6TTHWt30SZ2NK/HmYOr+fI0/H8OTWtrxcMlwYYZkbmhllGAYWnXnZCOCHuIcio7L21pEX/PXtrQMTVNFuebT2Q8GihjoW00KeH8z4t7E+a7MFb427dX7MRYGHHGuu2dAUoDI/P5tz7FIQg83Uz4Jmnzh34Wc9uYLd5lTcRc6Mb7mOVHXO9ZLoVtxE7gB+apN+NkzhPhZjQToyvypwyzUZiHV9xtYj9abUuU5vXEdGTA4+KEy7iM25r7U1cqsVVWsXBckpEpprlvJ2FQbbajP9PZpvnSwFmbPDGFJf2uPs07xtav1F6fpAU9zSg8J+iagS9grmCccNcs4TrExWRCFLRupN2AC9SeLWCb2ux+3IMuqwNkJiiWYNzLMOHru2kxFGgc7+wd3bzREbgZJbYUHCmVchHVcUT2/dn240mSVnLoemP1z91VdxbUN3EwR0Hcp5LnTMqCSQ880QUmFjDFnd0huKXKrKrr61na/wVoUDrcQGg/DKgvGcDm6CqzeHfSM9EHqwbbYx4cZn36ZA1nDiNTMLSxHhn0="
|
||||||
|
script: npm run coverage
|
||||||
|
before_script:
|
||||||
|
- export TZ=Europe/Moscow
|
||||||
|
- date
|
||||||
|
- npm install codeclimate-test-reporter istanbul -g
|
||||||
|
after_script:
|
||||||
|
- codeclimate-test-reporter < ./coverage/lcov.info
|
||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- node_js: '0.10'
|
- node_js: 'lts/*'
|
||||||
before_install: npm -g i npm@2
|
|
||||||
- node_js: '0.12'
|
|
||||||
before_install: npm -g i npm@2
|
|
||||||
- node_js: '4'
|
|
||||||
before_install: npm -g i npm@2
|
|
||||||
|
|
||||||
|
|||||||
51
Gruntfile.js
51
Gruntfile.js
@@ -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'
|
|
||||||
]);
|
|
||||||
};
|
|
||||||
171
lib/index.js
171
lib/index.js
@@ -2,50 +2,120 @@
|
|||||||
|
|
||||||
const xml = require('xml');
|
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 pushIfConditionTrue(condition, array, data) {
|
||||||
|
if (condition) {
|
||||||
array.push(data);
|
array.push(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateXML(data) {
|
/**
|
||||||
|
* @param related
|
||||||
|
* @param itemValues
|
||||||
|
* @param relatedInfinity
|
||||||
|
*/
|
||||||
|
function addRelated(related, itemValues, relatedInfinity) {
|
||||||
|
let relatedResult = related.map(function (rel) {
|
||||||
|
return {
|
||||||
|
link: [{
|
||||||
|
_attr: {
|
||||||
|
'url': rel.link,
|
||||||
|
'img': rel.image_url
|
||||||
|
}
|
||||||
|
}, rel.text]
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
let channel = [];
|
if (relatedInfinity) {
|
||||||
|
relatedResult.push({
|
||||||
|
_attr: {'type': 'infinity'}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
channel.push({title: {_cdata: data.title}});
|
pushIfConditionTrue(related, itemValues, {'yandex:related': relatedResult});
|
||||||
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 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let item_values = [];
|
/**
|
||||||
|
* Items processing
|
||||||
|
* @param items
|
||||||
|
* @param channel
|
||||||
|
*/
|
||||||
|
function items(items, channel) {
|
||||||
|
items.forEach(function (item) {
|
||||||
|
let itemValues = [];
|
||||||
|
itemValues.push({_attr: {'turbo': item.turboEnabled ? 'true' : 'false'}});
|
||||||
|
itemValues.push({link: item.url});
|
||||||
|
|
||||||
item_values.push({_attr: {'turbo': 'true'}});
|
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});
|
||||||
|
|
||||||
item_values.push({link: item.url});
|
let img = '', menu = '';
|
||||||
item_values.push({'turbo:source': item.url});
|
|
||||||
|
|
||||||
ifTruePush(item.date, item_values, {pubDate: new Date(item.date).toGMTString()});
|
|
||||||
ifTruePush(item.author, item_values, {author: item.author});
|
|
||||||
|
|
||||||
let img = '';
|
|
||||||
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>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.menu) {
|
if (Array.isArray(item.menu)) {
|
||||||
menu = '<menu>' + item.menu + '</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;
|
let fullContent = '<header>' + img + ' <h1>' + item.title + '</h1>' + menu + '</header>' + item.content;
|
||||||
|
|
||||||
item_values.push({'turbo:content': {_cdata: fullContent}});
|
pushGoals(item, itemValues);
|
||||||
channel.push({item: item_values});
|
|
||||||
|
|
||||||
|
itemValues.push({'turbo:content': {_cdata: fullContent}});
|
||||||
|
|
||||||
|
if (typeof item.related !== 'undefined') {
|
||||||
|
addRelated(item.related, itemValues, item.relatedfinity);
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.push({item: itemValues});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param data
|
||||||
|
* @returns {{rss: *[]}}
|
||||||
|
*/
|
||||||
|
function generateXML(data) {
|
||||||
|
|
||||||
|
let channel = [];
|
||||||
|
|
||||||
|
channel.push({title: {_cdata: data.title}});
|
||||||
|
channel.push({link: data.link});
|
||||||
|
channel.push({description: {_cdata: data.description || data.title}});
|
||||||
|
channel.push({language: data.language});
|
||||||
|
|
||||||
|
items(data.items, channel);
|
||||||
|
|
||||||
let _attr = {
|
let _attr = {
|
||||||
'xmlns:yandex': 'http://news.yandex.ru',
|
'xmlns:yandex': 'http://news.yandex.ru',
|
||||||
@@ -62,28 +132,47 @@ function generateXML(data) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function YTurbo(options, items) {
|
/**
|
||||||
|
* @param data
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
function itemData(data) {
|
||||||
|
return {
|
||||||
|
title: data.title || '',
|
||||||
|
description: data.description || '',
|
||||||
|
image_url: data.image_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 || '',
|
||||||
|
goals: data.goals || [],
|
||||||
|
turboEnabled: data.turboEnabled !== undefined ? data.turboEnabled: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Base function
|
||||||
|
* @param options
|
||||||
|
* @param items
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function TR(options, items) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
|
||||||
this.title = options.title || 'Untitled';
|
this.title = options.title || '';
|
||||||
|
this.link = options.link || '';
|
||||||
this.description = options.description || '';
|
this.description = options.description || '';
|
||||||
this.link = options.link;
|
this.language = options.language || 'ru';
|
||||||
|
|
||||||
this.items = items || [];
|
this.items = items || [];
|
||||||
|
|
||||||
this.item = function (options) {
|
this.item = function (data) {
|
||||||
options = options || {};
|
data = data || {};
|
||||||
let item = {
|
this.items.push(itemData(data));
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
this.items.push(item);
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -92,4 +181,4 @@ function YTurbo(options, items) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = YTurbo;
|
module.exports = TR;
|
||||||
|
|||||||
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "turbo-rss",
|
"name": "turbo-rss",
|
||||||
"version": "1.0.1",
|
"version": "1.1.1",
|
||||||
"description": "RSS based, feed generator for Yandex turbo",
|
"description": "RSS based, feed generator for Yandex turbo",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"yandex",
|
"yandex",
|
||||||
@@ -11,16 +11,16 @@
|
|||||||
"main": "lib/index",
|
"main": "lib/index",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tape test --tap | tap-difflet",
|
"test": "tape test --tap | tap-difflet",
|
||||||
"lint": "grunt lint",
|
"coverage": "istanbul cover tape test -- -R spec"
|
||||||
"test:browser": "prova -b"
|
|
||||||
},
|
},
|
||||||
"homepage": "http://github.com/lightair/yandex-turbo",
|
"homepage": "https://github.com/LightAir/turbo-rss",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LightAir",
|
"name": "LightAir",
|
||||||
"email": "public@softroot.ru"
|
"email": "public@softroot.ru"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"LightAir <public@softroot.ru>",
|
"LightAir <public@softroot.ru>",
|
||||||
|
"Ivan Pilyugin (aka Archer)",
|
||||||
"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",
|
||||||
@@ -34,10 +34,10 @@
|
|||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "http://github.com/lightair/yandex-turbo.git"
|
"url": "https://github.com/LightAir/turbo-rss.git"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "http://github.com/lightair/yandex-turbo/issues"
|
"url": "https://github.com/LightAir/turbo-rss/issues"
|
||||||
},
|
},
|
||||||
"testling": {
|
"testling": {
|
||||||
"files": "test/*.js",
|
"files": "test/*.js",
|
||||||
@@ -56,6 +56,7 @@
|
|||||||
"xml": "1.0.1"
|
"xml": "1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"eslint": "^4.19.1",
|
||||||
"folderify": "^1.1.0",
|
"folderify": "^1.1.0",
|
||||||
"grunt": "^0.4.5",
|
"grunt": "^0.4.5",
|
||||||
"grunt-cli": "^0.1.13",
|
"grunt-cli": "^0.1.13",
|
||||||
|
|||||||
86
readme.md
86
readme.md
@@ -1,15 +1,12 @@
|
|||||||
## WIP
|
|
||||||
|
|
||||||
## turbo-rss
|
## turbo-rss
|
||||||
|
|
||||||
[](https://travis-ci.org/lightair/turbo-rss)
|
[](https://codeclimate.com/github/LightAir/turbo-rss/maintainability)
|
||||||

|
[](https://codeclimate.com/github/LightAir/turbo-rss/test_coverage)
|
||||||

|
[](https://travis-ci.org/LightAir/turbo-rss)
|
||||||
|
[](https://www.npmjs.com/package/turbo-rss)
|
||||||
|

|
||||||
|
|
||||||
|
>Генератор RSS разметки для сервиса Турбо-страницы https://yandex.ru/support/webmaster/turbo/connection.html
|
||||||
>Генератор RSS разметки для сервиса Турбо-страницы
|
|
||||||
|
|
||||||
>ПРЕДУПРЕЖДЕНИЕ! Работа в процессе
|
|
||||||
|
|
||||||
### Использование
|
### Использование
|
||||||
|
|
||||||
@@ -24,12 +21,11 @@ var feed = new TR(feedOptions);
|
|||||||
##### `Опции канала`
|
##### `Опции канала`
|
||||||
|
|
||||||
* `title` **string** Название RSS-канала.
|
* `title` **string** Название RSS-канала.
|
||||||
* `description` _optional_ **string** Описание канала одним предложением. Не используйте HTML-разметку..
|
* `link` **url string** Домен сайта, данные которого транслируются.
|
||||||
* `author` _optional_ **string** If included it is the name of the item's creator. **(Будет удалено)**
|
* `description` _optional_ **string** Описание канала одним предложением. Не используйте HTML-разметку.
|
||||||
* `link` **url string** Домен сайта, данные которого транслируются..
|
* `language` _optional_ **string** Язык статьи по стандарту ISO 639-1. По умолчанию ru.
|
||||||
* `pubDate` _optional_ **Date object or date string** The publication date for content in the feed **(Будет удалено)**
|
|
||||||
|
|
||||||
*Будет добавлено в новых версиях turbo:analytics, turbo:adNetwork*
|
*Будет добавлено в новых версиях turbo:analytics, turbo:adNetwork, на текущий момент можно добавить в интерфейсе Яндекс Вебмастер*
|
||||||
|
|
||||||
#### Добавление страницы в канал
|
#### Добавление страницы в канал
|
||||||
```js
|
```js
|
||||||
@@ -39,13 +35,30 @@ feed.item(itemOptions);
|
|||||||
##### itemOptions
|
##### itemOptions
|
||||||
|
|
||||||
* `title` **string** Заголовок страницы.
|
* `title` **string** Заголовок страницы.
|
||||||
* `image_url` **url string** Адрес изображения, которое используется в качестве обложки. Изображение может быть в любом формате.
|
* `image_url` _optional_ **url string** Адрес изображения, которое используется в качестве обложки. Изображение может быть в любом формате.
|
||||||
* `url` **url string** URL страницы сайта, для которой нужно сформировать Турбо-страницу.
|
* `link` **url string** URL страницы сайта, для которой нужно сформировать Турбо-страницу.
|
||||||
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
* `author` _optional_ **string** Автор статьи, размещенной на странице.
|
||||||
* `date` **string** Время публикации контента на сайте источника.
|
* `date` или `pubDate` **string** Время публикации контента на сайте источника. Передается в формате RFC-822.
|
||||||
* `content` **string** Содержимое страницы
|
* `content` **string** Содержимое страницы
|
||||||
|
* `menu` _optional_ **array** Внимание! Меню будет отображаться только в том случае, если в настройках на странице Яндекс Вебмастер -> Турбо-страницы -> Настройки, содержимое 'Меню Турбо-страниц' пустое!
|
||||||
|
* `related` _optional_ **array** Аффилированные ссылки `yandex:related` в конце статьи. Вы можете разместить ссылки на другие ресурсы или настроить отображение непрерывной ленты статей, реализованной, например с помощью AJAX.
|
||||||
|
* `relatedfinity` _optional_ **bool** Непрерывная лента статей
|
||||||
|
* `turboSource` _optional_ **string** URL страницы-источника, который можно передать в Яндекс.Метрику.
|
||||||
|
* `turboTopic` _optional_ **string** Заголовок страницы, который можно передать в Яндекс.Метрику.
|
||||||
|
* `goals` _optional_ **array** массив типа: { _id_ - внутренний идентификатор цели (turbo-goal-id), _name_ - имя цели, _counter_id_ - id счётчика яндекс-метрики }
|
||||||
|
* `turboEnabled`_optional_ **bool** Принудительная установка атрибута "turbo". По умолчанию true. Установка в false позволит скрыть отображение турбо-страницы
|
||||||
|
###### menu array
|
||||||
|
menu должен содержать массив объектов со следующими опциями:
|
||||||
|
|
||||||
*Будет добавлено в новых версиях turbo:source, turbo:topic, yandex:related, menu, pubDate как алиас date*
|
* `link` **url string** ссылка
|
||||||
|
* `text` **string** текст ссылки. не должен содержать html
|
||||||
|
|
||||||
|
###### related array
|
||||||
|
related должен содержать массив объектов со следующими опциями:
|
||||||
|
|
||||||
|
* `link` **url string** ссылка на статью
|
||||||
|
* `image_url` **url string** ссылка на изображение к статье
|
||||||
|
* `text` **string** текст ссылки. Не должен содержать html
|
||||||
|
|
||||||
##### Получение XML
|
##### Получение XML
|
||||||
|
|
||||||
@@ -59,31 +72,58 @@ var xml = feed.xml();
|
|||||||
```js
|
```js
|
||||||
var TR = require('turbo-rss');
|
var TR = require('turbo-rss');
|
||||||
|
|
||||||
/* lets create feed */
|
|
||||||
var feed = new TR({
|
var feed = new TR({
|
||||||
title: 'title',
|
title: 'title',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
link: 'http://example.com',
|
link: 'http://example.com',
|
||||||
});
|
});
|
||||||
|
|
||||||
/* loop over data and add to feed */
|
|
||||||
feed.item({
|
feed.item({
|
||||||
title: 'item title',
|
title: 'item title',
|
||||||
image_url: 'http://example.com/example.png',
|
image_url: 'http://example.com/example.png',
|
||||||
url: 'http://example.com/article4?this&that',
|
url: 'http://example.com/article4?this&that',
|
||||||
author: 'LightAir',
|
author: 'LightAir',
|
||||||
date: 'May 27, 2012',
|
date: 'May 27, 2012',
|
||||||
content: '<p>hello</p>'
|
content: '<p>hello</p>',
|
||||||
|
goals: [{
|
||||||
|
type: "yandex",
|
||||||
|
id: "turbo-goal-id",
|
||||||
|
counter_id: "12345",
|
||||||
|
name: "order",
|
||||||
|
}],
|
||||||
|
menu: [{
|
||||||
|
link: 'http://example.com/',
|
||||||
|
text: 'Главная'
|
||||||
|
}, {
|
||||||
|
link: 'http://example.com/about',
|
||||||
|
text: 'О сайте'
|
||||||
|
}]
|
||||||
|
related: [{
|
||||||
|
link: 'http://example.com/related/post1',
|
||||||
|
image_url: 'http://example.com/i/img1.jpg',
|
||||||
|
text: 'related link text 1'
|
||||||
|
}, {
|
||||||
|
link: 'http://example.com/related/post2',
|
||||||
|
image_url: 'http://example.com/i/img2.jpg',
|
||||||
|
text: 'related link text 2'
|
||||||
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
// cache the xml to send to clients
|
|
||||||
var xml = feed.xml();
|
var xml = feed.xml();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Тестирование
|
## Тестирование
|
||||||
|
|
||||||
Для запуска тестов выполните `npm test`. На текущий момен покрытие тестами не 100%
|
Для запуска тестов выполните `npm test`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ npm test
|
$ npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Спасибо
|
||||||
|
|
||||||
|
@jahglow
|
||||||
|
|
||||||
|
@vvmspace
|
||||||
|
|
||||||
|
@crackosok
|
||||||
@@ -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[Untitled]]></title><link>http://github.com/LightAir/turbo-rss</link><description><![CDATA[Untitled]]></description><language>ru</language></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/><link></link><description/><language>ru</language></channel></rss>
|
||||||
|
|||||||
@@ -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></link><turbo:source></turbo:source><turbo:content><![CDATA[<header> <h1>No title</h1></header>undefined]]></turbo:content></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></link><turbo:content><![CDATA[<header> <h1></h1></header>undefined]]></turbo:content></item></channel></rss>
|
||||||
|
|||||||
1
test/expectedOutput/defaultItemTurboFalse.xml
Normal file
1
test/expectedOutput/defaultItemTurboFalse.xml
Normal file
@@ -0,0 +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="false"><link></link><turbo:content><![CDATA[<header> <h1></h1></header>undefined]]></turbo:content></item></channel></rss>
|
||||||
@@ -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[Untitled]]></title><link>http://github.com/LightAir/turbo-rss</link><description><![CDATA[Untitled]]></description><language>ru</language><item turbo="true"><link></link><turbo:source></turbo:source><turbo:content><![CDATA[<header> <h1>No title</h1></header>undefined]]></turbo:content></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/><link></link><description/><language>ru</language><item turbo="true"><link></link><turbo:content><![CDATA[<header> <h1></h1></header>undefined]]></turbo:content></item></channel></rss>
|
||||||
|
|||||||
1
test/expectedOutput/goal.xml
Normal file
1
test/expectedOutput/goal.xml
Normal file
@@ -0,0 +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&that</link><pubDate>Sat, 26 May 2018 21:00:00 GMT</pubDate><author>vvm.space</author><turbo:goal type="yandex" turbo-goal-id="turbo-goal-id" name="order" id="12345"/><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>
|
||||||
1
test/expectedOutput/menu.xml
Normal file
1
test/expectedOutput/menu.xml
Normal file
@@ -0,0 +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&that</link><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><menu><a href="http://example.com/">Главная</a><a href="http://example.com/about">О сайте</a></menu></header><p>hello</p>]]></turbo:content><yandex:related type="infinity"><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><item turbo="true"><link></link><turbo:content><![CDATA[<header> <h1></h1></header>undefined]]></turbo:content></item></channel></rss>
|
||||||
1
test/expectedOutput/relatedItem.xml
Normal file
1
test/expectedOutput/relatedItem.xml
Normal file
@@ -0,0 +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&that</link><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>
|
||||||
1
test/expectedOutput/relatedItemInfinity.xml
Normal file
1
test/expectedOutput/relatedItemInfinity.xml
Normal file
@@ -0,0 +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&that</link><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 type="infinity"><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>
|
||||||
175
test/index.js
175
test/index.js
@@ -1,27 +1,25 @@
|
|||||||
// prova is a wrapper for tape
|
/*
|
||||||
// use npm run test:browser to run tests in a browser
|
* use npm test to run tests
|
||||||
var test = require('tape');
|
*/
|
||||||
|
const test = require('tape');
|
||||||
|
const TR = require('..');
|
||||||
|
|
||||||
var YTurbo = require('..');
|
const includeFolder = require('include-folder');
|
||||||
|
const expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
|
||||||
var includeFolder = require('include-folder');
|
|
||||||
var expectedOutput = includeFolder(__dirname + '/expectedOutput', /.*\.xml$/);
|
|
||||||
|
|
||||||
require('mockdate').set('Wed, 10 Dec 2014 19:04:57 GMT');
|
require('mockdate').set('Wed, 10 Dec 2014 19:04:57 GMT');
|
||||||
|
|
||||||
test('empty feed', function (t) {
|
test('empty feed', function (t) {
|
||||||
t.plan(2);
|
t.plan(2);
|
||||||
var feed = new YTurbo();
|
let feed = new TR();
|
||||||
t.equal(feed.xml(), expectedOutput.default.trim());
|
t.equal(feed.xml(), expectedOutput.default.trim());
|
||||||
feed.item();
|
feed.item();
|
||||||
t.equal(feed.xml(), expectedOutput.defaultOneItem.trim());
|
t.equal(feed.xml(), expectedOutput.defaultOneItem.trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
test('default item', function (t) {
|
test('default item', function (t) {
|
||||||
|
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
|
let feed = new TR({
|
||||||
var feed = new YTurbo({
|
|
||||||
title: 'title',
|
title: 'title',
|
||||||
description: 'description',
|
description: 'description',
|
||||||
link: 'http://example.com/rss.xml',
|
link: 'http://example.com/rss.xml',
|
||||||
@@ -32,3 +30,158 @@ test('default item', function(t) {
|
|||||||
|
|
||||||
t.equal(feed.xml(), expectedOutput.defaultItem.trim());
|
t.equal(feed.xml(), expectedOutput.defaultItem.trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('default item turbo false', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
let feed = new TR({
|
||||||
|
title: 'title',
|
||||||
|
description: 'description',
|
||||||
|
link: 'http://example.com/rss.xml',
|
||||||
|
site_url: 'http://example.com',
|
||||||
|
});
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
turboEnabled: false
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.defaultItemTurboFalse.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('related item', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
let feed = new TR({
|
||||||
|
title: 'title',
|
||||||
|
description: 'description',
|
||||||
|
link: 'http://example.com/rss.xml',
|
||||||
|
site_url: 'http://example.com'
|
||||||
|
});
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
title: 'item title',
|
||||||
|
image_url: 'http://example.com/example.png',
|
||||||
|
url: 'http://example.com/article4?this&that',
|
||||||
|
author: 'LightAir',
|
||||||
|
date: 'May 27, 2018 00:00 AM',
|
||||||
|
menu: '<a href="http://example.com/page1.html">Текст ссылки</a> <a href="http://example.com/page2.html">Текст ссылки</a>',
|
||||||
|
content: '<p>hello</p>',
|
||||||
|
related: [{
|
||||||
|
link: 'http://example.com/related/post1',
|
||||||
|
image_url: 'http://example.com/i/img1.jpg',
|
||||||
|
text: 'related link text 1'
|
||||||
|
}, {
|
||||||
|
link: 'http://example.com/related/post2',
|
||||||
|
image_url: 'http://example.com/i/img2.jpg',
|
||||||
|
text: 'related link text 2'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.relatedItem.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('related item', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
let feed = new TR({
|
||||||
|
title: 'title',
|
||||||
|
description: 'description',
|
||||||
|
link: 'http://example.com/rss.xml',
|
||||||
|
site_url: 'http://example.com'
|
||||||
|
});
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
title: 'item title',
|
||||||
|
image_url: 'http://example.com/example.png',
|
||||||
|
url: 'http://example.com/article4?this&that',
|
||||||
|
author: 'LightAir',
|
||||||
|
date: 'May 27, 2018 00:00 AM',
|
||||||
|
content: '<p>hello</p>',
|
||||||
|
relatedfinity: true,
|
||||||
|
related: [{
|
||||||
|
link: 'http://example.com/related/post1',
|
||||||
|
image_url: 'http://example.com/i/img1.jpg',
|
||||||
|
text: 'related link text 1'
|
||||||
|
}, {
|
||||||
|
link: 'http://example.com/related/post2',
|
||||||
|
image_url: 'http://example.com/i/img2.jpg',
|
||||||
|
text: 'related link text 2'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.relatedItemInfinity.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('menu', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
let feed = new TR({
|
||||||
|
title: 'title',
|
||||||
|
description: 'description',
|
||||||
|
link: 'http://example.com/rss.xml',
|
||||||
|
site_url: 'http://example.com'
|
||||||
|
});
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
title: 'item title',
|
||||||
|
image_url: 'http://example.com/example.png',
|
||||||
|
url: 'http://example.com/article4?this&that',
|
||||||
|
author: 'LightAir',
|
||||||
|
date: 'May 27, 2018 00:00 AM',
|
||||||
|
content: '<p>hello</p>',
|
||||||
|
relatedfinity: true,
|
||||||
|
menu: [{
|
||||||
|
link: 'http://example.com/',
|
||||||
|
text: 'Главная',
|
||||||
|
}, {
|
||||||
|
link: 'http://example.com/about',
|
||||||
|
text: 'О сайте',
|
||||||
|
}],
|
||||||
|
related: [{
|
||||||
|
link: 'http://example.com/related/post1',
|
||||||
|
image_url: 'http://example.com/i/img1.jpg',
|
||||||
|
text: 'related link text 1'
|
||||||
|
}, {
|
||||||
|
link: 'http://example.com/related/post2',
|
||||||
|
image_url: 'http://example.com/i/img2.jpg',
|
||||||
|
text: 'related link text 2'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
feed.item({});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.menu.trim());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('goals', function (t) {
|
||||||
|
t.plan(1);
|
||||||
|
let feed = new TR({
|
||||||
|
title: 'title',
|
||||||
|
description: 'description',
|
||||||
|
link: 'http://example.com/rss.xml',
|
||||||
|
site_url: 'http://example.com'
|
||||||
|
});
|
||||||
|
|
||||||
|
feed.item({
|
||||||
|
title: 'item title',
|
||||||
|
image_url: 'http://example.com/example.png',
|
||||||
|
url: 'http://example.com/article4?this&that',
|
||||||
|
author: 'vvm.space',
|
||||||
|
date: 'May 27, 2018 00:00 AM',
|
||||||
|
menu: '<a href="http://example.com/page1.html">Текст ссылки</a> <a href="http://example.com/page2.html">Текст ссылки</a>',
|
||||||
|
goals: [{
|
||||||
|
type: "yandex",
|
||||||
|
id: "turbo-goal-id",
|
||||||
|
counter_id: "12345",
|
||||||
|
name: "order",
|
||||||
|
}],
|
||||||
|
content: '<p>hello</p>',
|
||||||
|
related: [{
|
||||||
|
link: 'http://example.com/related/post1',
|
||||||
|
image_url: 'http://example.com/i/img1.jpg',
|
||||||
|
text: 'related link text 1'
|
||||||
|
}, {
|
||||||
|
link: 'http://example.com/related/post2',
|
||||||
|
image_url: 'http://example.com/i/img2.jpg',
|
||||||
|
text: 'related link text 2'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
t.equal(feed.xml(), expectedOutput.goal.trim());
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user