From 64dc23054898fae5bb90cab6a74dba50da174eec Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 12 Aug 2021 16:08:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E4=B8=AD=E5=9B=BD=E7=BA=BA?= =?UTF-8?q?=E7=BB=87=E7=BB=8F=E6=B5=8E=E4=BF=A1=E6=81=AF=E7=BD=91=E8=B5=84?= =?UTF-8?q?=E8=AE=AF=20(#7213)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/new-media.md | 24 +++++++++++++++++++ lib/router.js | 2 ++ lib/routes/ctei/news.js | 51 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 lib/routes/ctei/news.js diff --git a/docs/new-media.md b/docs/new-media.md index c7db6a967514d2..3113333b2eb1a5 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -2452,6 +2452,30 @@ column 为 third 时可选的 category: +## 中国纺织经济信息网 + +### 资讯 + + + +| 要闻 | 国内 | 国际 | 企业 | 品牌 | 外贸 | 政策 | 科技 | 流行 | 服装 | 家纺 | +| ------ | -------- | -------- | ------- | ----- | ----- | ------ | ---------- | ------- | ------- | ------- | +| newsyw | domestic | internal | company | brand | trade | policy | Technology | fashion | apparel | hometex | + + + +## 中国计算机学会 + +### 新闻 + + + +| CCF 新闻 | CCF 聚焦 | ACM 信息 | +| ---------- | -------- | -------- | +| Media_list | Focus | ACM_News | + + + ## 中国机械工程学会 ### 学会新闻 diff --git a/lib/router.js b/lib/router.js index 1c6d52792604ac..50da0f0c89921a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4158,6 +4158,8 @@ router.get('/tanchinese/:category?', require('./routes/tanchinese')); // Harvard router.get('/harvard/health/blog', require('./routes/universities/harvard/health/blog')); +// 中国纺织经济信息网 +router.get('/ctei/news/:id?', require('./routes/ctei/news')); // 时事一点通 router.get('/ssydt/article/:id?', require('./routes/ssydt/article')); diff --git a/lib/routes/ctei/news.js b/lib/routes/ctei/news.js new file mode 100644 index 00000000000000..b104c2c7656281 --- /dev/null +++ b/lib/routes/ctei/news.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const id = ctx.params.id || 'bwzq'; + + const rootUrl = 'http://news.ctei.cn'; + const currentUrl = `${rootUrl}/${id}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.news_text ul li a') + .map((_, item) => { + item = $(item); + + return { + title: item.text(), + link: `${currentUrl}${item.attr('href').replace(/\./, '')}`, + }; + }) + .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('.TRS_Editor').html(); + item.pubDate = parseDate(item.link.match(/\/t(\d{8})_\d+.htm/)[1], 'YYYYMMDD'); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};