fix(route): mckinsey insights (#11052)

This commit is contained in:
Tony
2022-10-11 06:44:12 +11:00
committed by GitHub
parent 63e141ab05
commit b5001bbc30
7 changed files with 158 additions and 55 deletions

View File

@@ -304,13 +304,32 @@ TokenInsight 官方亦有提供 RSS可参考 <https://api.tokeninsight.com/re
<Route author="Fatpandac" example="/laohu8/personal/3527667596890271" path="/laohu8/personal/:id" :paramsDesc="['用户 ID见网址链接']" rssbud="1" radar="1"/>
## 麦肯锡中国
## 麦肯锡
<Route author="laampui" example="/mckinsey/autos" path="/mckinsey/:category?" :paramsDesc="['默认为全部,见下表']">
### 洞见
| 汽车 | 金融服务 | 数字化 | 消费者 | 医药与医疗 | 麦肯锡全球研究院 | 全球基础材料 | 创新 | 宏观经济 | 制造业 | 人才与领导力 | 技术,媒体与通信 | 城市化与可持续发展 | 资本项目和基础设施 | 旅游、运输和物流 |
| ----- | ----------------- | ------------------- | --------- | -------------------------- | ------------------------- | ------ | ---------- | ------------ | ------------- | ----------------- | ---------------------------- | --------------------------- | ------------------------------- | -------- |
| autos | banking-insurance | business-technology | consumers | healthcare-pharmaceuticals | mckinsey-global-institute | 全球基础材料 | innovation | macroeconomy | manufacturing | talent-leadership | technology-media-and-telecom | urbanization-sustainability | capital-projects-infrastructure | 交通运输与物流 |
<Route author="laampui" example="/mckinsey/cn" path="/mckinsey/cn/:category?" :paramsDesc="['分类,见下表,默认为全部']" radar="1" rssbud="1">
| 分类 | 分类名 |
| -- | --------- |
| 25 | 全部洞见 |
| 2 | 汽车 |
| 3 | 金融服务 |
| 4 | 消费者 |
| 5 | 医药 |
| 7 | 数字化 |
| 8 | 制造业 |
| 9 | 私募 |
| 10 | 技术,媒体与通信 |
| 12 | 城市化与可持续发展 |
| 13 | 创新 |
| 16 | 人才与领导力 |
| 18 | 宏观经济 |
| 19 | 麦肯锡全球研究院 |
| 37 | 麦肯锡季刊 |
| 41 | 资本项目和基础设施 |
| 42 | 旅游、运输和物流 |
| 45 | 全球基础材料 |
</Route>

View File

@@ -3397,7 +3397,7 @@ router.get('/clb/commentary/:lang?', lazyloadRouteHandler('./routes/clb/commenta
router.get('/iie/blog', lazyloadRouteHandler('./routes/iie/blog'));
// McKinsey Greater China
router.get('/mckinsey/:category?', lazyloadRouteHandler('./routes/mckinsey/index'));
// router.get('/mckinsey/:category?', lazyloadRouteHandler('./routes/mckinsey/index'));
// 超理论坛
router.get('/chaoli/:channel?', lazyloadRouteHandler('./routes/chaoli/index'));

View File

@@ -1,49 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category || '';
const title = {
autos: '汽车',
'banking-insurance': '金融服务',
'business-technology': '数字化',
consumers: '消费者',
'healthcare-pharmaceuticals': '医药与医疗',
'mckinsey-global-institute': '麦肯锡全球研究院',
全球基础材料: '全球基础材料',
innovation: '创新',
macroeconomy: '宏观经济',
manufacturing: '制造业',
'talent-leadership': '人才与领导力',
'technology-media-and-telecom': '技术,媒体与通信',
'urbanization-sustainability': '城市化与可持续发展',
'capital-projects-infrastructure': '资本项目和基础设施',
交通运输与物流: '旅游、运输和物流',
};
const response = await got.get(`https://www.mckinsey.com.cn/insights/${category}`);
const $ = cheerio.load(response.data);
const articles = $('.fusion-column h4 a')
.map((index, ele) => ({
title: $(ele).text(),
link: $(ele).attr('href'),
}))
.get();
const item = await Promise.all(
articles.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const res = await got.get(item.link);
const doc = cheerio.load(res.data);
item.description = doc('#content').html();
return item;
})
)
);
ctx.state.data = {
title: category ? `McKinsey Greater China - ${title[category]}` : `McKinsey Greater China`,
link: 'https://www.mckinsey.com.cn/',
item,
};
};

View File

@@ -0,0 +1,79 @@
const categories = {
// https://www.mckinsey.com.cn/wp-json/wp/v2/categories?parent=25&per_page=100
2: {
name: '汽车',
slug: 'autos',
},
3: {
name: '金融服务',
slug: 'banking-insurance',
},
4: {
name: '消费者',
slug: 'consumers',
},
5: {
name: '医药',
slug: 'healthcare-pharmaceuticals',
},
7: {
name: '数字化',
slug: 'business-technology',
},
8: {
name: '制造业',
slug: 'manufacturing',
},
9: {
name: '私募',
slug: 'private-equity',
},
10: {
name: '技术,媒体与通信',
slug: 'technology-media-and-telecom',
},
12: {
name: '城市化与可持续发展',
slug: 'urbanization-sustainability-insights',
},
13: {
name: '创新',
slug: 'innovation',
},
16: {
name: '人才与领导力',
slug: 'talent-leadership',
},
18: {
name: '宏观经济',
slug: 'macroeconomy',
},
19: {
name: '麦肯锡全球研究院',
slug: 'mckinsey-global-institute',
},
25: {
name: '洞见',
slug: 'insights',
},
37: {
name: '麦肯锡季刊',
slug: 'mckinsey-season-publication',
},
41: {
name: '资本项目和基础设施',
slug: 'capital-projects-infrastructure',
},
42: {
name: '旅游、运输和物流',
slug: 'transport-logistics',
},
45: {
name: '全球基础材料',
slug: 'global-basic-material',
},
};
module.exports = {
categories,
};

View File

@@ -0,0 +1,37 @@
// use stock `got` package as a workaround for
// https://github.com/DIYgod/RSSHub/issues/8239
// https://github.com/DIYgod/RSSHub/pull/8288
const got = require('got');
const { parseDate } = require('@/utils/parse-date');
const { categories } = require('./categoryMap');
const baseUrl = 'https://www.mckinsey.com.cn';
const endpoint = `${baseUrl}/wp-json`;
module.exports = async (ctx) => {
const { category = '25' } = ctx.params;
if (isNaN(category)) {
categories.find((c) => c.slug === category);
}
const posts = await got(`${endpoint}/wp/v2/posts`, {
searchParams: {
per_page: ctx.query.limit ? Number(ctx.query.limit) : 50,
categories: category,
},
}).json();
const items = posts.map((item) => ({
title: item.title.rendered,
description: item.content.rendered,
link: item.link,
guid: item.guid.rendered,
pubDate: parseDate(item.date_gmt),
}));
ctx.state.data = {
title: category ? `McKinsey Greater China - ${categories[category].name}` : `McKinsey Greater China`,
link: `${baseUrl}/${category !== '25' ? `${categories[25].slug}/${categories[category].slug}` : categories[category].slug}/`,
item: items,
};
};

14
lib/v2/mckinsey/radar.js Normal file
View File

@@ -0,0 +1,14 @@
const { categories } = require('./cn/categoryMap');
module.exports = {
'mckinsey.com.cn': {
_name: 'McKinsey Greater China',
'.': [
{
title: '洞见',
docs: 'https://docs.rsshub.app/finance.html#mai-ken-xi',
source: ['/insights/:category', '/insights'],
target: (params) => `/mckinsey/cn${params.category ? `/${categories.find((c) => c.slug === params.category).key}` : ''}`,
},
],
},
};

View File

@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/cn/:category?', require('./cn/index'));
};