Files
RSSHub/lib/v2/chinafactcheck/utils.js
T
377c2c4d57 feat(route): add chinafactcheck (#9611)
* add(route): 首席经济学家论坛

* fix(route) : merge from FledgeXu

* fix(route) : merge from FledgeXu

* (fix) typo

* feat(route): remove radar from radar-rules.js

* Update lib/v2/chinacef/hot.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/chinacef/router.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/chinacef/maintainer.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/chinacef/experts.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/chinacef/experts.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update hot.js

* Update experts.js

* docs: fix Route's path and example of chinacef

* Revert "docs: fix Route's path and example of chinacef"

This reverts commit 0ec9e7d9d6d1eff201482e38a26b255478861a5c.

* docs: fix Route's path and example of chinacef

* feat(route): add chinafactcheck

Co-authored-by: linkai <linkai@mochasoft.com.cn>
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2022-04-25 10:37:48 +08:00

61 lines
1.6 KiB
JavaScript

const { art } = require('@/utils/render');
const path = require('path');
const cheerio = require('cheerio');
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const siteLink = 'https://chinafactcheck.com';
const renderDesc = (desc) =>
art(path.join(__dirname, 'templates/description.art'), {
desc,
});
const cleanDom = (dom) => {
dom('*[style]').removeAttr('style');
dom('br').remove();
dom('span:empty').remove();
dom('span').each((_, el) => {
if (dom(el).html().trim() === '&nbsp;') {
dom(el).remove();
}
});
dom('p:empty').remove();
dom('p').each((_, el) => {
if (dom(el).html().trim() === '') {
dom(el).remove();
}
});
return dom;
};
const getArticleDetail = async (link) => {
const response = await got(link);
const $ = cleanDom(cheerio.load(response.data));
const title = $('.content-head h2').text().trim();
const author = $('.content-persons p span:last').text().trim();
const time = parseDate($('.content-time').text().trim(), 'YYYY-MM-DD');
const description = {
article: $('div[class=content-list-box]').html(),
};
return new ArticleDetail(title, author, time, renderDesc(description));
};
class ArticleDetail {
constructor(title, author, time, description) {
this.title = title;
this.author = author;
this.time = time;
this.description = description;
}
}
module.exports = {
siteLink,
renderDesc,
cleanDom,
getArticleDetail,
ArticleDetail,
};