feat(route): economist espresso (#9853)

* feat(route): economist espresso

* fix: add item.link
This commit is contained in:
Tony
2022-05-30 23:48:18 +08:00
committed by GitHub
parent e1ee28267e
commit 7b4c332fb0
12 changed files with 168 additions and 85 deletions
+7 -3
View File
@@ -448,15 +448,19 @@ Language
### Category
<RouteEn author="ImSingee" example="/the-economist/latest" path="/the-economist/:endpoint" :paramsDesc="['Category name, can be found on the [official page](https://www.economist.com/rss). For example, https://www.economist.com/china/rss.xml to china']"/>
<RouteEn author="ImSingee" example="/economist/latest" path="/economist/:endpoint" :paramsDesc="['Category name, can be found on the [official page](https://www.economist.com/rss). For example, https://www.economist.com/china/rss.xml to china']" radar="1" rssbud="1"/>
### Espresso
<RouteEn author="TonyRL" example="/economist/espresso" path="/economist/espresso" radar="1" rssbud="1"/>
### GRE Vocabulary
<RouteEn author="xyqfer" example="/the-economist/gre-vocabulary" path="/the-economist/gre-vocabulary" />
<RouteEn author="xyqfer" example="/economist/gre-vocabulary" path="/economist/gre-vocabulary" />
### Download
<RouteEn author="nczitzk" example="/the-economist/download" path="/the-economist/download" >
<RouteEn author="nczitzk" example="/economist/download" path="/economist/download" >
The download site: http://www.cgx02.xyz/index.php?dir=/te
+7 -3
View File
@@ -394,15 +394,19 @@ Solidot 提供的 feed:
### 分类
<Route author="ImSingee" example="/the-economist/latest" path="/the-economist/:endpoint" :paramsDesc="['分类名称,可在 [官方 RSS 页面 ](https://www.economist.com/rss) 找到,例如 https://www.economist.com/china/rss.xml 即为 china']"/>
<Route author="ImSingee" example="/economist/latest" path="/economist/:endpoint" :paramsDesc="['分类名称,可在 [官方 RSS 页面 ](https://www.economist.com/rss) 找到,例如 https://www.economist.com/china/rss.xml 即为 china']" radar="1" rssbud="1"/>
### Espresso
<Route author="TonyRL" example="/economist/espresso" path="/economist/espresso" radar="1" rssbud="1"/>
### GRE Vocabulary
<Route author="xyqfer" example="/the-economist/gre-vocabulary" path="/the-economist/gre-vocabulary" />
<Route author="xyqfer" example="/economist/gre-vocabulary" path="/economist/gre-vocabulary" radar="1" rssbud="1"/>
### 下载
<Route author="nczitzk" example="/the-economist/download" path="/the-economist/download" >
<Route author="nczitzk" example="/economist/download" path="/economist/download" >
下载站:<http://www.cgx02.xyz/index.php?dir=/te>
+4 -4
View File
@@ -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'));
-48
View File
@@ -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,
};
};
@@ -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: `
<img src="${wordInfo.image.url}"><br>
Source: <a href="${wordInfo.sourceUrl}">${wordInfo.sourceTitle}</a>
`,
pubDate: new Date(time).toUTCString(),
link: wordInfo.url,
},
],
};
};
+50
View File
@@ -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],
};
};
+42
View File
@@ -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,
};
};
+19
View File
@@ -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,
})),
};
};
+6
View File
@@ -0,0 +1,6 @@
module.exports = {
'/download': ['nczitzk'],
'/espresso': ['TonyRL'],
'/gre-vocabulary': ['xyqfer'],
'/:endpoint': ['ImSingee'],
};
+27
View File
@@ -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',
},
],
},
};
+6
View File
@@ -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'));
};