feat(route): bjedu (#14288)
This commit is contained in:
parent
4adcd60986
commit
e399ca73c8
|
|
@ -0,0 +1,48 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://gh.bjedu.cn';
|
||||
const { urlPath = 'zxtzgg' } = ctx.params;
|
||||
|
||||
const { data: response, url: link } = await got(`${baseUrl}/ghsite/${urlPath}/index.html`);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
const list = $('.content li a')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text().trim(),
|
||||
link: item.attr('href').startsWith('http') ? item.attr('href').replace(/^http:/, 'https:') : new URL(item.attr('href'), link).href,
|
||||
pubDate: item.prev().length ? timezone(parseDate(item.prev().text().trim(), 'YYYY-MM-DD'), +8) : null,
|
||||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (!item.link.endsWith('.html')) {
|
||||
return item;
|
||||
}
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
item.title = item.title.endsWith('...') ? $('.con-h h1').text().trim() : item.title;
|
||||
item.pubDate = timezone(parseDate($('.con-h span').eq(0).text().trim(), 'YYYY-MM-DD HH:mm:ss'), +8);
|
||||
item.author = $('.con-h span').eq(1).text().trim();
|
||||
item.description = $('.content_font').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('head title').text(),
|
||||
link,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -69,6 +69,7 @@ module.exports = {
|
|||
'/zhengce/:category?': ['nczitzk'],
|
||||
// province
|
||||
'/anhui/kjt/:path?': ['nczitzk'],
|
||||
'/beijing/bjedu/gh/:urlPath?': ['TonyRL'],
|
||||
'/beijing/bphc/:channel': ['bigfei'],
|
||||
'/beijing/jw/tzgg': ['nczitzk'],
|
||||
'/beijing/kw/:channel': ['Fatpandac'],
|
||||
|
|
|
|||
|
|
@ -297,6 +297,17 @@ module.exports = {
|
|||
},
|
||||
],
|
||||
},
|
||||
'bjedu.gov.cn': {
|
||||
_name: '北京市教育委员会',
|
||||
gh: [
|
||||
{
|
||||
title: '教育科学规划网 - 通用',
|
||||
docs: 'https://docs.rsshub.app/routes/government#bei-jing-shi-jiao-yu-ke-xue-gui-hua-wang',
|
||||
source: ['/ghsite/:urlPath/index.html', '/ghsite/:urlPath'],
|
||||
target: '/gov/beijing/bjedu/gh/:urlPath',
|
||||
},
|
||||
],
|
||||
},
|
||||
'bphc.com.cn': {
|
||||
_name: '北京保障房中心有限公司',
|
||||
gycpt: [
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ module.exports = function (router) {
|
|||
router.get('/zhengce/:category*', require('./zhengce'));
|
||||
// province
|
||||
router.get(/anhui\/kjt\/([\w/-]+)?/, require('./anhui/kjt'));
|
||||
router.get('/beijing/bjedu/gh/:urlPath?', require('./beijing/bjedu/gh'));
|
||||
router.get(/beijing\/bphc(\/[\w/-]+)?/, require('./beijing/bphc'));
|
||||
router.get('/beijing/jw/tzgg', require('./beijing/jw/tzgg'));
|
||||
router.get('/beijing/kw/:channel', require('./beijing/kw/index'));
|
||||
|
|
|
|||
|
|
@ -224,6 +224,18 @@
|
|||
| announcement | project |
|
||||
</Route>
|
||||
|
||||
## 北京市教育科学规划网 {#bei-jing-shi-jiao-yu-ke-xue-gui-hua-wang}
|
||||
|
||||
### 通用 {#bei-jing-shi-jiao-yu-ke-xue-gui-hua-wang-tong-yong}
|
||||
|
||||
<Route author="TonyRL" example="/gov/beijing/bjedu/gh" path="/gov/beijing/bjedu/gh/:urlPath?" paramsDesc={['路径,默认为 `zxtzgg`']} radar="1">
|
||||
:::tip
|
||||
路径处填写对应页面 URL 中 `https://gh.bjedu.cn/ghsite/` 和 `/index.html` 之间的字段。下面是一个例子。
|
||||
|
||||
若订阅 [通知公告](https://gh.bjedu.cn/ghsite/zxtzgg/index.html) 则将对应页面 URL `https://gh.bjedu.cn/ghsite/zxtzgg/index.html` 中 `https://gh.bjedu.cn/ghsite/` 和 `/index.html` 之间的字段 `zxtzgg` 作为路径填入。此时路由为 [`/gov/beijing/bjedu/gh/zxtzgg`](https://rsshub.app/gov/beijing/bjedu/gh/zxtzgg)
|
||||
:::
|
||||
</Route>
|
||||
|
||||
## 北京市教育委员会 {#bei-jing-shi-jiao-yu-wei-yuan-hui}
|
||||
|
||||
### 通知公告 {#bei-jing-shi-jiao-yu-wei-yuan-hui-tong-zhi-gong-gao}
|
||||
|
|
|
|||
Loading…
Reference in New Issue