From b5001bbc30740e2dfdfe422c52882d26b33e9822 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 11 Oct 2022 06:44:12 +1100 Subject: [PATCH] fix(route): mckinsey insights (#11052) --- docs/finance.md | 29 ++++++++++-- lib/router.js | 2 +- lib/routes/mckinsey/index.js | 49 ------------------- lib/v2/mckinsey/cn/categoryMap.js | 79 +++++++++++++++++++++++++++++++ lib/v2/mckinsey/cn/index.js | 37 +++++++++++++++ lib/v2/mckinsey/radar.js | 14 ++++++ lib/v2/mckinsey/router.js | 3 ++ 7 files changed, 158 insertions(+), 55 deletions(-) delete mode 100644 lib/routes/mckinsey/index.js create mode 100644 lib/v2/mckinsey/cn/categoryMap.js create mode 100644 lib/v2/mckinsey/cn/index.js create mode 100644 lib/v2/mckinsey/radar.js create mode 100644 lib/v2/mckinsey/router.js diff --git a/docs/finance.md b/docs/finance.md index 8d9679eef..76d076992 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -304,13 +304,32 @@ TokenInsight 官方亦有提供 RSS,可参考 -## 麦肯锡中国 +## 麦肯锡 - +### 洞见 -| 汽车 | 金融服务 | 数字化 | 消费者 | 医药与医疗 | 麦肯锡全球研究院 | 全球基础材料 | 创新 | 宏观经济 | 制造业 | 人才与领导力 | 技术,媒体与通信 | 城市化与可持续发展 | 资本项目和基础设施 | 旅游、运输和物流 | -| ----- | ----------------- | ------------------- | --------- | -------------------------- | ------------------------- | ------ | ---------- | ------------ | ------------- | ----------------- | ---------------------------- | --------------------------- | ------------------------------- | -------- | -| 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 | 交通运输与物流 | + + +| 分类 | 分类名 | +| -- | --------- | +| 25 | 全部洞见 | +| 2 | 汽车 | +| 3 | 金融服务 | +| 4 | 消费者 | +| 5 | 医药 | +| 7 | 数字化 | +| 8 | 制造业 | +| 9 | 私募 | +| 10 | 技术,媒体与通信 | +| 12 | 城市化与可持续发展 | +| 13 | 创新 | +| 16 | 人才与领导力 | +| 18 | 宏观经济 | +| 19 | 麦肯锡全球研究院 | +| 37 | 麦肯锡季刊 | +| 41 | 资本项目和基础设施 | +| 42 | 旅游、运输和物流 | +| 45 | 全球基础材料 | diff --git a/lib/router.js b/lib/router.js index 321ef60a7..6851599b0 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/mckinsey/index.js b/lib/routes/mckinsey/index.js deleted file mode 100644 index 5f74b6fab..000000000 --- a/lib/routes/mckinsey/index.js +++ /dev/null @@ -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, - }; -}; diff --git a/lib/v2/mckinsey/cn/categoryMap.js b/lib/v2/mckinsey/cn/categoryMap.js new file mode 100644 index 000000000..bb4271fa4 --- /dev/null +++ b/lib/v2/mckinsey/cn/categoryMap.js @@ -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, +}; diff --git a/lib/v2/mckinsey/cn/index.js b/lib/v2/mckinsey/cn/index.js new file mode 100644 index 000000000..d8fc60a80 --- /dev/null +++ b/lib/v2/mckinsey/cn/index.js @@ -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, + }; +}; diff --git a/lib/v2/mckinsey/radar.js b/lib/v2/mckinsey/radar.js new file mode 100644 index 000000000..67d420cd7 --- /dev/null +++ b/lib/v2/mckinsey/radar.js @@ -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}` : ''}`, + }, + ], + }, +}; diff --git a/lib/v2/mckinsey/router.js b/lib/v2/mckinsey/router.js new file mode 100644 index 000000000..4bef0a3a7 --- /dev/null +++ b/lib/v2/mckinsey/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/cn/:category?', require('./cn/index')); +};