-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
37 lines (32 loc) · 960 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var Promise = require('promise');
var summarize = require('summarize');
var summary = require('node-summary');
var superagent = require('superagent');
var unfluff = require('unfluff');
var summarizeP = Promise.denodeify(summary.summarize);
module.exports.getPage = function (uri) {
'use strict';
return new Promise(function (resolve, reject) {
superagentGetP(uri).then(function (data) {
var text = data.text;
var pageContent = unfluff(text);
pageContent.raw = text;
pageContent.stats = summarize(text);
summarizeP(pageContent.title, pageContent.text).then(function (res) {
pageContent.summary = res;
resolve(pageContent);
}, reject);
}, reject);
});
};
function superagentGetP(uri) {
'use strict';
return new Promise(function (resolve, reject) {
superagent.get(uri).end(function (err, res) {
if (err) {
return reject(err);
}
resolve(res);
});
});
}