feat: add 东莞教研网 (#4879)
This commit is contained in:
parent
26cd2cb2c8
commit
561e8ba4a6
|
|
@ -235,6 +235,18 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||
|
||||
<Route author="LogicJake" example="/kpmg/insights" path="/kpmg/insights" />
|
||||
|
||||
## 东莞教研网
|
||||
|
||||
### 信息公开
|
||||
|
||||
<Route author="nczitzk" example="/dgjyw/news" path="/dgjyw/:type" :paramsDesc="['分类']">
|
||||
|
||||
| 动态 | 公示 | 通知 |
|
||||
| ---- | ------------ | ------ |
|
||||
| news | announcement | notice |
|
||||
|
||||
</Route>
|
||||
|
||||
## 福利资源 - met.red
|
||||
|
||||
### 福利资源 - met.red
|
||||
|
|
|
|||
|
|
@ -2795,4 +2795,7 @@ router.get('/law/jh', require('./routes/law/jh'));
|
|||
// Mobilism
|
||||
router.get('/mobilism/release', require('./routes/mobilism/release'));
|
||||
|
||||
// 东莞教研网
|
||||
router.get('/dgjyw/:type', require('./routes/dgjyw/index'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
const url = require('url');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const rootUrl = 'http://zxls.dgjyw.com/';
|
||||
|
||||
const config = {
|
||||
news: {
|
||||
link: '/node/57620',
|
||||
title: '动态',
|
||||
},
|
||||
announcement: {
|
||||
link: '/node/57725',
|
||||
title: '公示',
|
||||
},
|
||||
notice: {
|
||||
link: '/node/57621',
|
||||
title: '通知',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const cfg = config[ctx.params.type];
|
||||
if (!cfg) {
|
||||
throw Error('Bad category. See <a href="https://docs.rsshub.app/other.html#dong-guan-jiao-yan-wang">docs</a>');
|
||||
}
|
||||
|
||||
const currentUrl = url.resolve(rootUrl, cfg.link);
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('ul.list-ul')
|
||||
.eq(2)
|
||||
.find('li')
|
||||
.slice(0, 20)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const a = item.find('a[title]');
|
||||
return {
|
||||
title: a.text(),
|
||||
link: a.attr('href'),
|
||||
pubDate: new Date(new Date().getFullYear().toString().substr(0, 2) + item.find('span').text()).toUTCString(),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const res = await got({ method: 'get', url: item.link });
|
||||
const content = cheerio.load(res.data);
|
||||
|
||||
item.description = content('div.text').html();
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '东莞教研网 - ' + cfg.title,
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue