Rinser/paleo.js

126 lines
2.9 KiB
JavaScript

var outputFile = 'paleo',
RssBraider = require('rss-braider'),
fs = require('fs'),
ejs = require('ejs'),
read = require('fs').readFileSync,
join = require('path').join,
str = read(join(__dirname, '/templates/rss.ejs'), 'utf8'),
feeds = {};
// Pull feeds from config files: ,
// feeds.simple_test_feed = require("./config/feed").feed;
// Or define in-line
feeds.simple_test_feed = {
"feed_name": "feed",
"default_count": 1,
"no_cdata_fields": [], // Don't wrap these fields in CDATA tags
"meta": {
"title": "Paleo",
"description": "Combined Paleo Feed",
'site_url': 'http://pipes.silvrtree.co.uk/paleo.xml'
},
"plugins": ['filter_3_days', "fix_images", 'fix_scripts'],
"sources": [{
"count": 100,
"feed_url": "http://feeds.feedburner.com/PaleoPlan"
}, {
"count": 100,
"feed_url": "http://nomnompaleo.com/rss"
}, {
"count": 100,
"feed_url": "http://thepaleodiet.com/feed/"
}, {
"count": 100,
"feed_url": "http://paleoleap.com/feed/"
}, {
"count": 100,
"feed_url": "http://ultimatepaleoguide.com/feed/"
}, {
"count": 100,
"feed_url": "http://elanaspantry.com/feed/"
}, {
"count": 100,
"feed_url": "http://feeds.feedburner.com/Paleomg-PaleoRecipes"
}, {
"count": 100,
"feed_url": "http://civilizedcavemancooking.com/feed/"
}, {
"count": 100,
"feed_url": "http://www.ruled.me/feed/"
}/*, {
"count": 100,
"feed_url": "http://www.primalbro.com/blog?format=RSS"
}*/
]
};
var braider_options = {
feeds: feeds,
indent: " ",
date_sort_order: "desc", // Newest first
log_level: "error",
dedupe_fields: ['guid'],
plugins_directories: [__dirname + "/plugins/"]
};
var rss_braider = RssBraider.createClient(braider_options);
// Override logging level (debug, info, warn, err, off)
rss_braider.logger.level('error');
rss_braider.processFeed('simple_test_feed', 'json', function(err, data) {
if (err) {
return console.log(err);
}
var j = JSON.parse(data);
var ejsOutput = ejs.compile(str)(j);
fs.writeFile(__dirname + "/dist/" + outputFile + ".json", data, function(err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
/*fs.writeFile(__dirname + "/html/" + outputFile + ".html", ejsOutput, function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});*/
});
/*
rss_braider.processFeed('simple_test_feed', 'rss', function (err, data) {
if (err) {
return console.log(err);
}
fs.writeFile(__dirname + "/html/" + outputFile + ".xml", data, function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
});
*/