feat(route): add 中国工人出版社新闻中心 (#7303)
* feat(route): add 中国工人出版社新闻中心 * refactor: migrate to v2 * fix: parseDate typo in router.js Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
This commit is contained in:
@@ -3784,6 +3784,18 @@ column 为 third 时可选的 category:
|
||||
|
||||
</Route>
|
||||
|
||||
## 中国工人出版社
|
||||
|
||||
### 新闻中心
|
||||
|
||||
<Route author="nczitzk" example="/wp-china/news" path="/wp-china/news/:category?" :paramsDesc="['分类,见下表,默认为最新资讯']">
|
||||
|
||||
| 最新资讯 | 专题报道 |
|
||||
| ------ | ------- |
|
||||
| latest | stories |
|
||||
|
||||
</Route>
|
||||
|
||||
## 中国机械工程学会
|
||||
|
||||
### 学会新闻
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/news/:category?': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
const config = {
|
||||
latest: 'list-35b3413e4c03411d8f3726162570804f',
|
||||
stories: 'list-7224ef82da1b498eb24046a6c56ff566',
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category ?? 'latest';
|
||||
|
||||
const rootUrl = 'http://www.wp-china.com';
|
||||
const currentUrl = `${rootUrl}/f/${config[category]}.html`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.new_list')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.children('.fb').text(),
|
||||
link: `${rootUrl}${item.parent().attr('href')}`,
|
||||
pubDate: timezone(parseDate(item.children('.grey').text()), +8),
|
||||
};
|
||||
})
|
||||
.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('.wb100').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text().replace(' - Powered By gobestsoft', ''),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'wp-china.com': {
|
||||
_name: '中国工人出版社',
|
||||
'.': [
|
||||
{
|
||||
title: '新闻中心',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#zhong-guo-gong-ren-chu-ban-she',
|
||||
source: ['/'],
|
||||
target: '/wp-china/news',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/news/:category?', require('./news'));
|
||||
};
|
||||
Reference in New Issue
Block a user