2018-06-14 08:07:51 +00:00
|
|
|
const outputFile = 'news';
|
|
|
|
const RssBraider = require('rss-braider');
|
|
|
|
const fs = require('fs');
|
|
|
|
const ejs = require(
|
|
|
|
'ejs');
|
|
|
|
const read = require('fs').readFileSync;
|
|
|
|
const join = require('path').join;
|
|
|
|
const str = read(
|
2016-04-18 12:49:38 +00:00
|
|
|
join(__dirname, '/templates/rss.ejs'),
|
2018-06-14 08:07:51 +00:00
|
|
|
'utf8');
|
|
|
|
const feeds = {};
|
2016-04-18 12:49:38 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
const argv = require('yargs').argv;
|
2017-02-07 22:10:31 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
const log4js = require('log4js');
|
|
|
|
const logger = log4js.getLogger();
|
|
|
|
|
|
|
|
logger.level = 'trace';
|
2015-08-20 10:59:11 +00:00
|
|
|
|
|
|
|
// Pull feeds from config files: ,
|
|
|
|
// feeds.simple_test_feed = require("./config/feed").feed;
|
|
|
|
// Or define in-line
|
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
feeds.news = require('./news.json');
|
2018-06-01 09:24:32 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
logger.debug('news:', feeds.news);
|
2016-04-18 12:49:38 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
|
|
|
|
const braider_options = {
|
2016-04-18 12:49:38 +00:00
|
|
|
feeds: feeds,
|
2017-10-01 17:25:17 +00:00
|
|
|
indent: ' ',
|
|
|
|
date_sort_order: 'desc', // Newest first
|
|
|
|
log_level: 'warn',
|
2016-04-18 12:49:38 +00:00
|
|
|
dedupe_fields: ['link', 'guid'],
|
2017-10-01 17:25:17 +00:00
|
|
|
plugins_directories: [__dirname + '/plugins/']
|
2015-08-20 10:59:11 +00:00
|
|
|
};
|
2018-06-14 08:07:51 +00:00
|
|
|
const rss_braider = RssBraider.createClient(braider_options);
|
2015-08-20 10:59:11 +00:00
|
|
|
|
|
|
|
// Override logging level (debug, info, warn, err, off)
|
2016-02-12 13:10:16 +00:00
|
|
|
//rss_braider.logger.level('off');
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
function gatherNews() {
|
|
|
|
logger.info('Gathering news...');
|
|
|
|
rss_braider.processFeed('news', 'json', function (err, data) {
|
|
|
|
console.log('A');
|
|
|
|
if (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('B');
|
|
|
|
|
|
|
|
const j = JSON.parse(data);
|
|
|
|
|
|
|
|
console.log('C');
|
|
|
|
const ejsOutput = ejs.compile(str)(j);
|
|
|
|
|
|
|
|
console.log('D');
|
|
|
|
fs.writeFile(__dirname + '/dist/' + outputFile + '.html',
|
|
|
|
ejsOutput,
|
|
|
|
function (err) {
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
if (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return console.error(err);
|
|
|
|
}
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
console.log('The file was saved!');
|
|
|
|
});
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
fs.writeFile(__dirname + '/dist/' + outputFile + '.json',
|
|
|
|
data,
|
|
|
|
function (err) {
|
|
|
|
if (err) {
|
|
|
|
logger.error(err);
|
|
|
|
return console.error(err);
|
|
|
|
}
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
console.log('The file was saved!');
|
|
|
|
});
|
|
|
|
});
|
2015-08-20 10:59:11 +00:00
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
}
|
2015-08-20 10:59:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-14 08:07:51 +00:00
|
|
|
gatherNews();
|