feat(route): 添加计算机视觉专委会 (#10090)

* routes: 添加计算机视觉专委会

* fix: description render
This commit is contained in:
elxy 2022-07-14 23:30:22 +08:00 committed by GitHub
parent 823602e0a0
commit 878fc49339
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 112 additions and 0 deletions

View File

@ -286,6 +286,18 @@ path="/ctfhub/upcoming/:limit?"
<Route author="xfangbao" example="/jijitang/article/latest" path="/jijitang/article/:id" :paramsDesc="['类别latest 或者 recommand']"/>
## 计算机视觉专委
### 学术动态 - 分类
<Route author="elxy" example="/ccfcv/xsdt/xsqy" path="/ccfcv/:channel/:category" :paramsDesc="['频道,仅支持 `xsdt`', '分类,见下表,亦可在网站 url 里找到']">
| 学术前沿 | 热点征文 | 学术会议 |
| ---- | ---- | ---- |
| xsqy | rdzw | xshy |
</Route>
## 金山词霸
### 每日一句

68
lib/v2/ccfcv/index.js Normal file
View File

@ -0,0 +1,68 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
const rootUrl = 'http://ccfcv.ccf.org.cn';
const cateTitleMap = {
xsdt: {
xsqy: '学术前沿',
rdzw: '热点征文',
xshy: '学术会议',
},
};
module.exports = async (ctx) => {
const channel = ctx.params.channel;
const cate = ctx.params.category;
const url = `${rootUrl}/ccfcv/${channel}/${cate}/`;
const response = await got(url);
const $ = cheerio.load(response.data);
let items = $('div.article-item')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('h3 a').text(),
link: (cate === 'xsqy' ? rootUrl : '') + item.find('h3 a').attr('href'),
pubDate: parseDate(item.find('div p').text()),
};
});
if (cate === 'xsqy') {
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
let detailResponse;
try {
detailResponse = await got(item.link);
} catch (error) {
item.status = 404;
}
if (item.status !== 404) {
const content = cheerio.load(detailResponse.data);
const pdfUrl = content('div.g-box1 p a').attr('href');
item.description = art(path.join(__dirname, 'templates/description.art'), {
pdfUrl,
});
}
delete item.status;
return item;
})
)
);
}
ctx.state.data = {
title: `计算机视觉专委 - ${cateTitleMap[channel][cate]}`,
link: url,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/:channel/:category': ['elxy'],
};

25
lib/v2/ccfcv/radar.js Normal file
View File

@ -0,0 +1,25 @@
module.exports = {
'ccfcv.ccf.org.cn': {
_name: '计算机视觉专委会',
www: [
{
title: '学术动态 - 学术前沿',
docs: 'https://docs.rsshub.app/study.html#ji-suan-ji-shi-jue-zhuan-wei-hui',
source: ['/ccfcv/xsdt/xsqy/'],
target: '/ccfcv/xsdt/xsqy',
},
{
title: '学术动态 - 热点征文',
docs: 'https://docs.rsshub.app/study.html#ji-suan-ji-shi-jue-zhuan-wei-hui',
source: ['/ccfcv/xsdt/rdzw/'],
target: '/ccfcv/xsdt/rdzw',
},
{
title: '学术动态 - 学术会议',
docs: 'https://docs.rsshub.app/study.html#ji-suan-ji-shi-jue-zhuan-wei-hui',
source: ['/ccfcv/xsdt/xshy/'],
target: '/ccfcv/xsdt/xshy',
},
],
},
};

3
lib/v2/ccfcv/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:channel/:category', require('./index'));
};

View File

@ -0,0 +1 @@
<center><embed src="{{ pdfUrl }}"></center>