From 5b3b7ee17259944e722dcdc816d922784b626f46 Mon Sep 17 00:00:00 2001 From: nczitzk Date: Sun, 10 Jan 2021 21:09:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=95=99=E8=82=B2=E9=83=A8?= =?UTF-8?q?=E9=98=B3=E5=85=89=E9=AB=98=E8=80=83=E4=BF=A1=E6=81=AF=E5=85=AC?= =?UTF-8?q?=E5=BC=80=E5=B9=B3=E5=8F=B0=E6=8B=9B=E7=94=9F=E6=94=BF=E7=AD=96?= =?UTF-8?q?=E8=A7=84=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/study.md | 12 +++++++++ lib/router.js | 3 +++ lib/routes/chsi/zszcgd.js | 52 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 lib/routes/chsi/zszcgd.js diff --git a/docs/study.md b/docs/study.md index 042669c95b..f62eb0ca4d 100644 --- a/docs/study.md +++ b/docs/study.md @@ -388,6 +388,18 @@ pageClass: routes +## 阳光高考 + +### 教育部阳光高考信息公开平台招生政策规定 + + + +| 招生政策 | 深化考试招生制度改革 | 教育法律法规 | +| -------- | -------------------- | ------------ | +| dnzszc | zdgg | jyflfg | + + + ## 印象识堂 ### 印象剪藏 diff --git a/lib/router.js b/lib/router.js index 5bb0f656c3..d468cea63b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3780,4 +3780,7 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog')); // Caixin Latest router.get('/caixin/latest', require('./routes/caixin/latest')); +// 阳光高考 +router.get('/chsi/zszcgd/:category?', require('./routes/chsi/zszcgd')); + module.exports = router; diff --git a/lib/routes/chsi/zszcgd.js b/lib/routes/chsi/zszcgd.js new file mode 100644 index 0000000000..911a5f6f3f --- /dev/null +++ b/lib/routes/chsi/zszcgd.js @@ -0,0 +1,52 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || 'dnzszc'; + + const rootUrl = 'https://gaokao.chsi.com.cn'; + const currentUrl = `${rootUrl}/gkxx/zszcgd/${category}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.list ul li a') + .slice(0, 15) + .map((_, item) => { + item = $(item); + const link = item.attr('href'); + + return { + title: item.text(), + pubDate: new Date(item.prev().text()).toUTCString(), + link: link.indexOf('http') < 0 ? `${rootUrl}${link}` : link, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.list').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${$('.backb').text()} - 教育部阳光高考信息公开平台`, + link: currentUrl, + item: items, + }; +};