Skip to content

Commit

Permalink
feat(route): 中国纺织经济信息网资讯 (#7213)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored Aug 12, 2021
1 parent a7c483c commit 64dc230
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,30 @@ column 为 third 时可选的 category:

</Route>

## 中国纺织经济信息网

### 资讯

<Route author="nczitzk" example="/ctei/news/bwzq" path="/ctei/news/:id?" :paramsDesc="['分类 id,可在分类页的 URL 中找到,默认为本网专区']">

| 要闻 | 国内 | 国际 | 企业 | 品牌 | 外贸 | 政策 | 科技 | 流行 | 服装 | 家纺 |
| ------ | -------- | -------- | ------- | ----- | ----- | ------ | ---------- | ------- | ------- | ------- |
| newsyw | domestic | internal | company | brand | trade | policy | Technology | fashion | apparel | hometex |

</Route>

## 中国计算机学会

### 新闻

<Route author="nczitzk" example="/ccf/news" path="/ccf/news/:category?" :paramsDesc="['分类,见下表,默认为 CCF 新闻']">

| CCF 新闻 | CCF 聚焦 | ACM 信息 |
| ---------- | -------- | -------- |
| Media_list | Focus | ACM_News |

</Route>

## 中国机械工程学会

### 学会新闻
Expand Down
2 changes: 2 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
51 changes: 51 additions & 0 deletions lib/routes/ctei/news.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

0 comments on commit 64dc230

Please sign in to comment.