diff --git a/docs/government.md b/docs/government.md index a0078c5f30..7e9bd10136 100644 --- a/docs/government.md +++ b/docs/government.md @@ -44,6 +44,22 @@ pageClass: routes +## 北京社科网 + +### 通用 + + + +::: tip 提示 + +路径处填写对应页面 URL 中 `https://www.bjsk.org.cn/` 和 `.html` 之间的字段。下面是一个例子。 + +若订阅 [社科资讯 > 社科要闻](https://www.bjsk.org.cn/newslist-1394-1474-0.html) 则将对应页面 URL 中 `https://www.bjsk.org.cn/` 和 `.html` 之间的字段 `newslist-1394-1474-0` 作为路径填入。此时路由为 [`/bjsk/newslist-1394-1474-0`](https://rsshub.app/bjsk/newslist-1394-1474-0) + +::: + + + ## 北京市保障房中心有限公司 ### 北京市共有产权住房租赁服务平台 diff --git a/lib/v2/bjsk/index.js b/lib/v2/bjsk/index.js new file mode 100644 index 0000000000..4eb2ecfc42 --- /dev/null +++ b/lib/v2/bjsk/index.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const baseUrl = 'https://www.bjsk.org.cn'; + +module.exports = async (ctx) => { + const { path = 'newslist-1486-0-0' } = ctx.params; + const link = `${baseUrl}/${path}.html`; + const { data: response } = await got(link, { + https: { + rejectUnauthorized: false, + }, + }); + const $ = cheerio.load(response); + + const list = $('.article-list a') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.attr('title'), + link: `${baseUrl}${item.attr('href')}`, + pubDate: parseDate(item.find('.time').text(), 'YYYY.MM.DD'), + }; + }); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link, { + https: { + rejectUnauthorized: false, + }, + }); + const $ = cheerio.load(response); + item.description = $('.article-main').html(); + item.author = $('.info') + .text() + .match(/作者:(.*)\s+来源/)[1]; + return item; + }) + ) + ); + + ctx.state.data = { + title: $('head title').text(), + link, + image: 'https://www.bjsk.org.cn/favicon.ico', + item: items, + }; +}; diff --git a/lib/v2/bjsk/maintainer.js b/lib/v2/bjsk/maintainer.js new file mode 100644 index 0000000000..fc59b3430f --- /dev/null +++ b/lib/v2/bjsk/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:path?': ['TonyRL'], +}; diff --git a/lib/v2/bjsk/radar.js b/lib/v2/bjsk/radar.js new file mode 100644 index 0000000000..e952f13b10 --- /dev/null +++ b/lib/v2/bjsk/radar.js @@ -0,0 +1,13 @@ +module.exports = { + 'bjsk.org.cn': { + _name: '北京社科网', + '.': [ + { + title: '通用', + docs: 'https://docs.rsshub.app/government.html#bei-jing-she-ke-wang', + source: ['/*'], + target: (_, url) => `/bjsk/${url.split('/')[3].replace('.html', '')}`, + }, + ], + }, +}; diff --git a/lib/v2/bjsk/router.js b/lib/v2/bjsk/router.js new file mode 100644 index 0000000000..71d391a9c2 --- /dev/null +++ b/lib/v2/bjsk/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:path?', require('./index')); +};