feat(route): add 学工部 (#10673)
* feat(route): add 学工部 * Update lib/v2/bnu/dwxgb.js
This commit is contained in:
parent
86a6db92ba
commit
aedf5c8cb7
|
|
@ -288,6 +288,16 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
### 党委学生工作部
|
||||
|
||||
<Route author="Fatpandac" example="/bnu/dwxgb/xwzx/tzgg" path="/bnu/dwxgb/:category/:type" :paramsDesc="['大分类', '子分类,例子如下']">
|
||||
|
||||
`https://dwxgb.bnu.edu.cn/xwzx/tzgg/index.html`\
|
||||
则对应为\
|
||||
`/bnu/dwxgb/xwzx/tzgg`
|
||||
|
||||
</Route>
|
||||
|
||||
### 信息学院通知
|
||||
|
||||
<Route author="wzc-blog" example="/bjfu/it/xyxw" path="/bjfu/it/:type" :paramsDesc="['通知类别']">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { category, type } = ctx.params;
|
||||
|
||||
const rootUrl = 'https://dwxgb.bnu.edu.cn';
|
||||
let currentUrl = `${rootUrl}/${category}/${type}/index.html`;
|
||||
|
||||
let response;
|
||||
try {
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
} catch (e) {
|
||||
currentUrl = `${rootUrl}/${category}/${type}/index.htm`;
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
}
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('ul.container.list > li')
|
||||
.map((_, item) => ({
|
||||
title: $(item).find('a').text().trim(),
|
||||
pubDate: parseDate($(item).find('span').text()),
|
||||
link: `${rootUrl}/${category}/${type}/${$(item).find('a').attr('href')}`,
|
||||
}))
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('div.article.typo').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('div.breadcrumb1 > a:nth-child(3)').text()} - ${$('div.breadcrumb1 > a:nth-child(4)').text()}`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -4,10 +4,16 @@ module.exports = {
|
|||
'.': [
|
||||
{
|
||||
title: '经济与工商管理学院',
|
||||
docs: 'https://docs.rsshub.app/universities.html#bei-jing-shi-fan-da-xue-jing-ji-yu-gong-shang-guan-li-xue-yuan',
|
||||
docs: 'https://docs.rsshub.app/university.html#bei-jing-shi-fan-da-xue',
|
||||
source: ['/'],
|
||||
target: '/bs/:category?',
|
||||
},
|
||||
{
|
||||
title: '经济与工商管理学院',
|
||||
docs: 'https://docs.rsshub.app/university.html#bei-jing-shi-fan-da-xue',
|
||||
source: ['/'],
|
||||
target: '/bnu/dwxgb/:category/:type',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/bs/:category?', require('./bs'));
|
||||
router.get('/dwxgb/:category/:type', require('./dwxgb'));
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue