forked from rbren/mediumexporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-feed.js
23 lines (22 loc) · 841 Bytes
/
get-feed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var rssParser = require('rss-parser')
, fs = require('fs')
, path = require('path')
, getPost = require('./get-post');
module.exports = function(feedURL, outputPath, program, callback) {
let outputDir = outputPath || process.cwd() + "/posts";
rssParser.parseURL(feedURL, function(err, data) {
if (err) return callback(err);
Promise.all(data.feed.entries.map(entry => {
return new Promise((resolve, reject) => {
getPost(entry.link, program, function(err, text) {
if (err) return reject(err);
entry.filename = path.join(outputDir, entry.title.replace(/\W+/g, '_') + '.md');
fs.writeFile(entry.filename, text, err => {
if (err) return reject(err);
resolve(text);
})
});
})
})).then(_ => callback && callback(null, data));
})
}