diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index c7d7e6199..2427bef15 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -448,15 +448,19 @@ Language ### Category - + + +### Espresso + + ### GRE Vocabulary - + ### Download - + The download site: http://www.cgx02.xyz/index.php?dir=/te diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 832b2d2d9..9000c6459 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -394,15 +394,19 @@ Solidot 提供的 feed: ### 分类 - + + +### Espresso + + ### GRE Vocabulary - + ### 下载 - + 下载站: diff --git a/lib/router.js b/lib/router.js index 42b63f5eb..ac7351b95 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1566,10 +1566,10 @@ router.get('/saraba1st/thread/:tid', lazyloadRouteHandler('./routes/saraba1st/th router.get('/gradcafe/result/:type', lazyloadRouteHandler('./routes/gradcafe/result')); router.get('/gradcafe/result', lazyloadRouteHandler('./routes/gradcafe/result')); -// The Economist -router.get('/the-economist/download', lazyloadRouteHandler('./routes/the-economist/download')); -router.get('/the-economist/gre-vocabulary', lazyloadRouteHandler('./routes/the-economist/gre-vocabulary')); -router.get('/the-economist/:endpoint', lazyloadRouteHandler('./routes/the-economist/full')); +// The Economist migrated to v2 +// router.get('/the-economist/download', lazyloadRouteHandler('./routes/the-economist/download')); +// router.get('/the-economist/gre-vocabulary', lazyloadRouteHandler('./routes/the-economist/gre-vocabulary')); +// router.get('/the-economist/:endpoint', lazyloadRouteHandler('./routes/the-economist/full')); // 鼠绘漫画 router.get('/shuhui/comics/:id', lazyloadRouteHandler('./routes/shuhui/comics')); diff --git a/lib/routes/the-economist/full.js b/lib/routes/the-economist/full.js deleted file mode 100644 index 2cb9e70a9..000000000 --- a/lib/routes/the-economist/full.js +++ /dev/null @@ -1,48 +0,0 @@ -const parser = require('@/utils/rss-parser'); -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const endpoint = ctx.params.endpoint; - const feed = await parser.parseURL(`https://www.economist.com/${endpoint}/rss.xml`); - - const getFullText = async (link) => { - let content = await ctx.cache.get(link); - if (content) { - return content; - } - - const response = await got({ - method: 'get', - url: link, - }); - const $ = cheerio.load(response.data); - - $('aside').remove(); - $('div.ds-chapter-list').remove(); - content = $('div.article__lead-image').html(); - content += $('header.article__header').html(); - content += $('div.layout-article-body').attr('itemprop', 'text').html(); - - ctx.cache.set(link, content); - - return content; - }; - - const items = await Promise.all( - feed.items.slice(0, 10).map(async (item) => ({ - title: item.title, - description: await getFullText(item.link), - link: item.link, - guid: item.guid, - pubDate: item.pubDate, - })) - ); - - ctx.state.data = { - title: feed.title, - link: feed.link, - description: feed.description, - item: items, - }; -}; diff --git a/lib/routes/the-economist/gre-vocabulary.js b/lib/routes/the-economist/gre-vocabulary.js deleted file mode 100644 index 0429e9f10..000000000 --- a/lib/routes/the-economist/gre-vocabulary.js +++ /dev/null @@ -1,27 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const response = await got({ - method: 'get', - url: 'https://gre.economist.com/api/gre-vocabulary.json', - }); - - const wordInfo = response.data[0]; - const time = wordInfo.publishedDate; - - ctx.state.data = { - title: 'The Economist GRE Vocabulary', - link: 'https://gre.economist.com/gre-vocabulary', - item: [ - { - title: `${wordInfo.word} - ${time}`, - description: ` -
- Source: ${wordInfo.sourceTitle} - `, - pubDate: new Date(time).toUTCString(), - link: wordInfo.url, - }, - ], - }; -}; diff --git a/lib/routes/the-economist/download.js b/lib/v2/economist/download.js similarity index 100% rename from lib/routes/the-economist/download.js rename to lib/v2/economist/download.js diff --git a/lib/v2/economist/espresso.js b/lib/v2/economist/espresso.js new file mode 100644 index 000000000..6dbdd9c62 --- /dev/null +++ b/lib/v2/economist/espresso.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const config = require('@/config').value; + +const link = 'https://www.economist.com/the-world-in-brief'; + +module.exports = async (ctx) => { + const $ = await ctx.cache.tryGet( + link, + async () => { + const response = await got(link); + return cheerio.load(response.data); + }, + config.cache.routeExpire, + false + ); + + const gobbets = $('._gobbets ._gobbet p') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.text(), + description: item.html(), + link, + guid: item.text(), + }; + }); + + const articles = $('._articles ._article') + .toArray() + .map((item) => { + item = $(item); + const title = item.find('h3').text(); + item.find('h3').remove(); + return { + title, + description: item.html(), + link, + guid: item.text(), + }; + }); + + ctx.state.data = { + title: $('head title').text(), + link, + description: $('meta[property="og:description"]').attr('content'), + item: [...gobbets, ...articles], + }; +}; diff --git a/lib/v2/economist/full.js b/lib/v2/economist/full.js new file mode 100644 index 000000000..d43c5b961 --- /dev/null +++ b/lib/v2/economist/full.js @@ -0,0 +1,42 @@ +const parser = require('@/utils/rss-parser'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const getArticleDetail = async (link, ctx) => + await ctx.cache.tryGet(link, async () => { + const response = await got(link); + const $ = cheerio.load(response.data); + $('div.article-audio-player__center-tooltip').remove(); + const nextData = JSON.parse($('head script[type="application/ld+json"]').text()); + + const article = $('#new-article-template > div > div.css-wvfzu8 > div.css-mticar').html() + $('#new-article-template > div > div.css-wvfzu8 > div > div > section').html(); + const categories = nextData.keywords.map((k) => k); + + return { article, categories }; + }); + +module.exports = async (ctx) => { + const endpoint = ctx.params.endpoint; + const feed = await parser.parseURL(`https://www.economist.com/${endpoint}/rss.xml`); + + const items = await Promise.all( + feed.items.map(async (item) => { + const itemDetails = await getArticleDetail(item.link, ctx); + return { + title: item.title, + description: itemDetails.article, + link: item.link, + guid: item.guid, + pubDate: item.pubDate, + category: itemDetails.categories, + }; + }) + ); + + ctx.state.data = { + title: feed.title, + link: feed.link, + description: feed.description, + item: items, + }; +}; diff --git a/lib/v2/economist/gre-vocabulary.js b/lib/v2/economist/gre-vocabulary.js new file mode 100644 index 000000000..39bb747b3 --- /dev/null +++ b/lib/v2/economist/gre-vocabulary.js @@ -0,0 +1,19 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: 'https://gre.economist.com/api/keywords.json', + }); + + const word = response.data; + + ctx.state.data = { + title: 'The Economist GRE Vocabulary', + link: 'https://gre.economist.com/gre-advice/gre-vocabulary/which-words-study/most-common-gre-vocabulary-list-organized-difficulty', + item: word.map((item) => ({ + title: item, + description: item, + })), + }; +}; diff --git a/lib/v2/economist/maintainer.js b/lib/v2/economist/maintainer.js new file mode 100644 index 000000000..5fbf14b7d --- /dev/null +++ b/lib/v2/economist/maintainer.js @@ -0,0 +1,6 @@ +module.exports = { + '/download': ['nczitzk'], + '/espresso': ['TonyRL'], + '/gre-vocabulary': ['xyqfer'], + '/:endpoint': ['ImSingee'], +}; diff --git a/lib/v2/economist/radar.js b/lib/v2/economist/radar.js new file mode 100644 index 000000000..aeda949c1 --- /dev/null +++ b/lib/v2/economist/radar.js @@ -0,0 +1,27 @@ +module.exports = { + 'economist.com': { + _name: 'The Economist', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/traditional-media.html#the-economist', + source: ['/:endpoint'], + target: '/economist/:endpoint', + }, + { + title: 'Espresso', + docs: 'https://docs.rsshub.app/traditional-media.html#the-economist', + source: ['/the-world-in-brief', '/espresso'], + target: '/economist/espresso', + }, + ], + gre: [ + { + title: 'GRE Vocabulary', + docs: 'https://docs.rsshub.app/traditional-media.html#the-economist', + source: ['/', '/gre-advice/gre-vocabulary/which-words-study/most-common-gre-vocabulary-list-organized-difficulty'], + target: '/economist/gre-vocabulary', + }, + ], + }, +}; diff --git a/lib/v2/economist/router.js b/lib/v2/economist/router.js new file mode 100644 index 000000000..ff1238bb0 --- /dev/null +++ b/lib/v2/economist/router.js @@ -0,0 +1,6 @@ +module.exports = (router) => { + router.get('/download', require('./download')); + router.get('/espresso', require('./espresso')); + router.get('/gre-vocabulary', require('./gre-vocabulary')); + router.get('/:endpoint', require('./full')); +};