From f50159ea2358d3e493ff86ab62344f5f5bca6407 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 14 Feb 2021 02:55:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=AF=8F=E7=BB=8F=E7=BD=91?= =?UTF-8?q?=E5=88=86=E7=B1=BB=20(#6896)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/finance.md | 18 +++++++++++++- docs/traditional-media.md | 6 ----- lib/router.js | 3 ++- lib/routes/nbd/index.js | 50 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 lib/routes/nbd/index.js diff --git a/docs/finance.md b/docs/finance.md index 8aab0ac0a..0a046d2e8 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -66,7 +66,7 @@ pageClass: routes ### 搜索关键字 -<Route author="nczitzk" example="/gelonghui/keyword/ 早报" path="/gelonghui/keyword/:keyword" :paramsDesc="[' 搜索关键字']/> + ## 金十数据 @@ -81,6 +81,22 @@ pageClass: routes +## 每经网 + +### 分类 + + + +| 头条 | 要闻 | 图片新闻 | 推荐 | +| ---- | ---- | -------- | ---- | +| 2 | 3 | 4 | 5 | + + + +### 重磅原创 + + + ## 上海证券交易所 ### 本所业务规则 diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 342d2d122..44bd94319 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -613,12 +613,6 @@ category 对应的关键词有 -## 每经网 - -### 重磅原创 - - - ## 南方周末 ### 新闻分类 diff --git a/lib/router.js b/lib/router.js index 3d9cd1c67..9d7ad6254 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2246,8 +2246,9 @@ router.get('/wineyun/:category', require('./routes/wineyun')); router.get('/xiaohongshu/user/:user_id/:category', require('./routes/xiaohongshu/user')); router.get('/xiaohongshu/board/:board_id', require('./routes/xiaohongshu/board')); -// 重磅原创-每经网 +// 每经网 router.get('/nbd/daily', require('./routes/nbd/article')); +router.get('/nbd/:id?', require('./routes/nbd/index')); // 快知 router.get('/kzfeed/topic/:id', require('./routes/kzfeed/topic')); diff --git a/lib/routes/nbd/index.js b/lib/routes/nbd/index.js new file mode 100644 index 000000000..7f9b7d963 --- /dev/null +++ b/lib/routes/nbd/index.js @@ -0,0 +1,50 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id || '3'; + + const rootUrl = 'http://www.nbd.com.cn'; + const currentUrl = `${rootUrl}/columns/${id}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.u-news-title a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: item.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.g-articl-text').html(); + item.pubDate = new Date(detailResponse.data.match(/"pubDate": "(.*)"/)[1]).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.u-channelname').text()} - 每经网`, + link: currentUrl, + item: items, + }; +};