fix(route): mckinsey insights (#11052)
This commit is contained in:
+1
-1
@@ -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'));
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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}` : ''}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/cn/:category?', require('./cn/index'));
|
||||
};
|
||||
Reference in New Issue
Block a user