feat(route): id param for shmeea (#14145)
* feat(route): id param for shmeea * fix(route): fix radar docs url in shmeea/self-study * fix(route): id?=08000 && block requests to binary files && fix code style ---------
This commit is contained in:
+35
-26
@@ -1,44 +1,53 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseURL = 'http://www.shmeea.edu.cn';
|
||||
const rootUrl = baseURL + '/page/08000/index.html';
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
const id = ctx.params.id ?? '08000';
|
||||
const baseURL = 'https://www.shmeea.edu.cn';
|
||||
const link = `${baseURL}/page/${id}/index.html`;
|
||||
|
||||
const data = response.data;
|
||||
const response = await got(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const title = `上海市教育考试院-${$('#main .pageh4-tit').text().trim()}`;
|
||||
|
||||
const list = $('#main .pageList li');
|
||||
const list = $('#main .pageList li')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('a').attr('title') || item.find('a').text(),
|
||||
link: new URL(item.find('a').attr('href'), baseURL).href,
|
||||
pubDate: parseDate(item.find('.listTime').text().trim(), 'YYYY-MM-DD'),
|
||||
};
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(async (i, item) => {
|
||||
item = $(item);
|
||||
const link = baseURL + item.find('a').attr('href');
|
||||
const description = await ctx.cache.tryGet(link, async () => {
|
||||
const result = await got.get(link);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (!item.link.endsWith('.html') || new URL(item.link).hostname !== new URL(baseURL).hostname) {
|
||||
return item;
|
||||
}
|
||||
|
||||
const result = await got(item.link);
|
||||
const $ = cheerio.load(result.data);
|
||||
|
||||
return $('#ivs_content').html();
|
||||
});
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
pubDate: new Date(item.find('.listTime').text()),
|
||||
link,
|
||||
description,
|
||||
};
|
||||
})
|
||||
const description = $('#ivs_content').html();
|
||||
const pbTimeText = $('#ivs_title .PBtime').text().trim();
|
||||
|
||||
item.description = description;
|
||||
item.pubDate = pbTimeText ? timezone(parseDate(pbTimeText, 'YYYY-MM-DD HH:mm:ss'), +8) : item.pubDate;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '上海市教育考试院',
|
||||
description: '消息速递',
|
||||
link: baseURL,
|
||||
title,
|
||||
link,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = {
|
||||
'/': ['jialinghui'],
|
||||
'/:id?': ['jialinghui', 'Misaka13514'],
|
||||
'/self-study': ['h2ws'],
|
||||
};
|
||||
|
||||
@@ -3,14 +3,17 @@ module.exports = {
|
||||
_name: '上海市教育考试院',
|
||||
www: [
|
||||
{
|
||||
title: '消息速递',
|
||||
docs: 'https://docs.rsshub.app/routes/other#shang-hai-shi-jiao-yu-kao-shi-yuan',
|
||||
source: ['/'],
|
||||
target: '/shmeea',
|
||||
title: '消息',
|
||||
docs: 'https://docs.rsshub.app/routes/study#shang-hai-shi-jiao-yu-kao-shi-yuan',
|
||||
source: ['/page/:id?/index.html'],
|
||||
target: (params, url, document) => {
|
||||
const li = document.querySelector('#main .pageList li');
|
||||
return li ? '/shmeea/:id?' : '';
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '自学考试通知公告',
|
||||
docs: 'https://docs.rsshub.app/routes/other#shang-hai-shi-jiao-yu-kao-shi-yuan',
|
||||
docs: 'https://docs.rsshub.app/routes/study#shang-hai-shi-jiao-yu-kao-shi-yuan',
|
||||
source: ['/page/04000/index.html', '/'],
|
||||
target: '/shmeea/self-study',
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/', require('./index'));
|
||||
router.get('/self-study', require('./self-study'));
|
||||
router.get('/:id?', require('./index'));
|
||||
};
|
||||
|
||||
@@ -335,11 +335,19 @@
|
||||
|
||||
## 上海市教育考试院 {#shang-hai-shi-jiao-yu-kao-shi-yuan}
|
||||
|
||||
### 消息速递 {#shang-hai-shi-jiao-yu-kao-shi-yuan-xiao-xi-su-di}
|
||||
官方网址:[https://www.shmeea.edu.cn](https://www.shmeea.edu.cn)
|
||||
|
||||
官方网址:[http://www.shmeea.edu.cn](http://www.shmeea.edu.cn)
|
||||
### 消息 {#shang-hai-shi-jiao-yu-kao-shi-yuan-xiao-xi}
|
||||
|
||||
<Route author="jialinghui" example="/shmeea" path="/shmeea" radar="1" />
|
||||
<Route author="jialinghui Misaka13514" example="/shmeea/08000" path="/shmeea/:id?" radar="1" paramsDesc={['页面 ID,可在 URL 中找到,默认为消息速递']}>
|
||||
:::tip
|
||||
例如:消息速递的网址为 `https://www.shmeea.edu.cn/page/08000/index.html`,则页面 ID 为 `08000`。
|
||||
:::
|
||||
|
||||
:::warning
|
||||
暂不支持大类分类和[院内动态](https://www.shmeea.edu.cn/page/19000/index.html)
|
||||
:::
|
||||
</Route>
|
||||
|
||||
### 自学考试通知公告 {#shang-hai-shi-jiao-yu-kao-shi-yuan-zi-xue-kao-shi-tong-zhi-gong-gao}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user