From 878fc493396ff2605bed4adf91cf2028f51097c4 Mon Sep 17 00:00:00 2001 From: elxy Date: Thu, 14 Jul 2022 23:30:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=B7=BB=E5=8A=A0=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=9C=BA=E8=A7=86=E8=A7=89=E4=B8=93=E5=A7=94=E4=BC=9A?= =?UTF-8?q?=20(#10090)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * routes: 添加计算机视觉专委会 * fix: description render --- docs/study.md | 12 +++++ lib/v2/ccfcv/index.js | 68 ++++++++++++++++++++++++++ lib/v2/ccfcv/maintainer.js | 3 ++ lib/v2/ccfcv/radar.js | 25 ++++++++++ lib/v2/ccfcv/router.js | 3 ++ lib/v2/ccfcv/templates/description.art | 1 + 6 files changed, 112 insertions(+) create mode 100644 lib/v2/ccfcv/index.js create mode 100644 lib/v2/ccfcv/maintainer.js create mode 100644 lib/v2/ccfcv/radar.js create mode 100644 lib/v2/ccfcv/router.js create mode 100644 lib/v2/ccfcv/templates/description.art diff --git a/docs/study.md b/docs/study.md index 9a52cfdbf..a100c6c66 100644 --- a/docs/study.md +++ b/docs/study.md @@ -286,6 +286,18 @@ path="/ctfhub/upcoming/:limit?" +## 计算机视觉专委 + +### 学术动态 - 分类 + + + +| 学术前沿 | 热点征文 | 学术会议 | +| ---- | ---- | ---- | +| xsqy | rdzw | xshy | + + + ## 金山词霸 ### 每日一句 diff --git a/lib/v2/ccfcv/index.js b/lib/v2/ccfcv/index.js new file mode 100644 index 000000000..0f3f43ddc --- /dev/null +++ b/lib/v2/ccfcv/index.js @@ -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, + }; +}; diff --git a/lib/v2/ccfcv/maintainer.js b/lib/v2/ccfcv/maintainer.js new file mode 100644 index 000000000..33ae7d4cb --- /dev/null +++ b/lib/v2/ccfcv/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:channel/:category': ['elxy'], +}; diff --git a/lib/v2/ccfcv/radar.js b/lib/v2/ccfcv/radar.js new file mode 100644 index 000000000..2cf9202fd --- /dev/null +++ b/lib/v2/ccfcv/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/ccfcv/router.js b/lib/v2/ccfcv/router.js new file mode 100644 index 000000000..f487b5733 --- /dev/null +++ b/lib/v2/ccfcv/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/:channel/:category', require('./index')); +}; diff --git a/lib/v2/ccfcv/templates/description.art b/lib/v2/ccfcv/templates/description.art new file mode 100644 index 000000000..402450ca5 --- /dev/null +++ b/lib/v2/ccfcv/templates/description.art @@ -0,0 +1 @@ +