2018-03-05 19:14:37 +00:00
|
|
|
const cheerio = require('cheerio');
|
|
|
|
|
2018-03-07 00:02:22 +00:00
|
|
|
const logger = require('log4js').getLogger('Euronews 🔧');
|
2018-03-05 19:14:37 +00:00
|
|
|
|
|
|
|
const { get, isEmpty } = require('lodash');
|
|
|
|
logger.level = 'debug';
|
|
|
|
|
|
|
|
const htmlTidy = /<(\/*?)(?!(em|p|br\s*\/|strong|h1|h2|h3))\w+?.+?>/gim;
|
|
|
|
|
|
|
|
function reduceArticle(body = '') {
|
|
|
|
if (body === '') return {};
|
|
|
|
|
|
|
|
const obj = {};
|
|
|
|
const $ = cheerio.load(body);
|
|
|
|
|
|
|
|
const title = $('meta[property="og:title"]').attr('content');
|
2018-03-05 19:21:00 +00:00
|
|
|
const image = `https://image.silvrtree.co.uk/640,fit,q80/${ $('meta[property="og:image"]').attr('content')}`;
|
2018-03-05 19:14:37 +00:00
|
|
|
|
|
|
|
const stuff = $('[itemprop="articleBody"]');
|
|
|
|
|
|
|
|
const html = [];
|
|
|
|
|
|
|
|
// stuff.children().each(function () {
|
|
|
|
stuff.each(function () {
|
|
|
|
html.push($(this).html());
|
|
|
|
});
|
|
|
|
|
2018-03-06 12:03:36 +00:00
|
|
|
html.push('<div class="endbumper"></div>');
|
|
|
|
// const outputHTML = html.join('').replace(htmlTidy, '');
|
|
|
|
const outputHTML = html.join('');
|
2018-03-05 19:14:37 +00:00
|
|
|
|
|
|
|
obj.title = title;
|
|
|
|
obj.image = image;
|
|
|
|
obj.html = outputHTML;
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { reduceArticle };
|