diff --git a/docs/new-media.md b/docs/new-media.md index 4e9c9434d..9e19a69cd 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -3784,6 +3784,18 @@ column 为 third 时可选的 category: +## 中国工人出版社 + +### 新闻中心 + + + +| 最新资讯 | 专题报道 | +| ------ | ------- | +| latest | stories | + + + ## 中国机械工程学会 ### 学会新闻 diff --git a/lib/v2/wp-china/maintainer.js b/lib/v2/wp-china/maintainer.js new file mode 100644 index 000000000..d4350891f --- /dev/null +++ b/lib/v2/wp-china/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:category?': ['nczitzk'], +}; diff --git a/lib/v2/wp-china/news.js b/lib/v2/wp-china/news.js new file mode 100644 index 000000000..8ad96177c --- /dev/null +++ b/lib/v2/wp-china/news.js @@ -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, + }; +}; diff --git a/lib/v2/wp-china/radar.js b/lib/v2/wp-china/radar.js new file mode 100644 index 000000000..55e46037f --- /dev/null +++ b/lib/v2/wp-china/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/wp-china/router.js b/lib/v2/wp-china/router.js new file mode 100644 index 000000000..1b7e39450 --- /dev/null +++ b/lib/v2/wp-china/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/news/:category?', require('./news')); +};