From 77dd3c130e95aaf35a352ca46c4263e0889b32b5 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 19 Feb 2022 18:52:20 +0800 Subject: [PATCH] feat(route): EU Disinfo Lab publications (#7294) * feat(route): EU Disinfo Lab publications * fix typo * fix lazyload images * refactor: migirate to v2 Co-authored-by: TonyRL --- docs/en/new-media.md | 6 ++++ docs/new-media.md | 6 ++++ lib/v2/disinfo/maintainer.js | 3 ++ lib/v2/disinfo/publications.js | 56 ++++++++++++++++++++++++++++++++++ lib/v2/disinfo/radar.js | 13 ++++++++ lib/v2/disinfo/router.js | 3 ++ 6 files changed, 87 insertions(+) create mode 100644 lib/v2/disinfo/maintainer.js create mode 100644 lib/v2/disinfo/publications.js create mode 100644 lib/v2/disinfo/radar.js create mode 100644 lib/v2/disinfo/router.js diff --git a/docs/en/new-media.md b/docs/en/new-media.md index a4177072b1..0812c7f788 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -169,6 +169,12 @@ Compared to the official one, the RSS feed generated by RSSHub not only has more +## EU Disinfo Lab + +### Publications + + + ## Europa Press ### Category diff --git a/docs/new-media.md b/docs/new-media.md index e09bad069d..f57d19a6ca 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -284,6 +284,12 @@ pageClass: routes +## EU Disinfo Lab + +### Publications + + + ## Europa Press ### 分类 diff --git a/lib/v2/disinfo/maintainer.js b/lib/v2/disinfo/maintainer.js new file mode 100644 index 0000000000..5c0e58f54d --- /dev/null +++ b/lib/v2/disinfo/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/publications': ['nczitzk'], +}; diff --git a/lib/v2/disinfo/publications.js b/lib/v2/disinfo/publications.js new file mode 100644 index 0000000000..ba0ba7413e --- /dev/null +++ b/lib/v2/disinfo/publications.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.disinfo.eu'; + const currentUrl = `${rootUrl}/publications`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.elementor-heading-title a') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + content('.wp-block-spacer').remove(); + content('.elementor-widget-container p').eq(0).remove(); + + content('img').each(function () { + content(this).attr('src', content(this).attr('data-lazy-src')); + }); + + item.description = content('.elementor-widget-theme-post-content').html(); + item.pubDate = parseDate(content('meta[property="article:modified_time"]').attr('content')); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/disinfo/radar.js b/lib/v2/disinfo/radar.js new file mode 100644 index 0000000000..70f91c835d --- /dev/null +++ b/lib/v2/disinfo/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'disinfo.eu': { + _name: 'EU Disinfo Lab', + '.': [ + { + title: 'Publications', + docs: 'https://docs.rsshub.app/new-media.html#eu-disinfo-lab', + source: ['/'], + target: '/disinfo/publications', + }, + ], + }, +}; diff --git a/lib/v2/disinfo/router.js b/lib/v2/disinfo/router.js new file mode 100644 index 0000000000..dfc1ff4ecf --- /dev/null +++ b/lib/v2/disinfo/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/publications', require('./publications')); +};