From f26cafb6c7b8d4e925c6d152f29310cf8eb66ce3 Mon Sep 17 00:00:00 2001 From: Jimmy Wang Date: Mon, 5 Aug 2019 11:32:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9E=9C=E5=A3=B3=20=E7=89=A9=E7=A7=8D?= =?UTF-8?q?=E6=97=A5=E5=8E=86=20(#2768)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat:果壳 物种日历 * feat:将‘果壳 物种日历’扩展至吃货研究所,美丽也是技术活 * 全文获取使用缓存 --- docs/other.md | 8 +++++++ lib/router.js | 1 + lib/routes/guokr/calendar.js | 46 ++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lib/routes/guokr/calendar.js diff --git a/docs/other.md b/docs/other.md index 6a9c792ce0..ff0d3aecb5 100644 --- a/docs/other.md +++ b/docs/other.md @@ -539,6 +539,14 @@ type 为 all 时,category 参数不支持 cost 和 free +### 果壳网专栏 + + +| 物种日历 | 吃货研究所 | 美丽也是技术活 | +| ------- | ---------| ------------ | +| calendar | institute | beauty | + + ## 后续 ### Live diff --git a/lib/router.js b/lib/router.js index 50f139d384..b2cf857145 100644 --- a/lib/router.js +++ b/lib/router.js @@ -696,6 +696,7 @@ router.get('/ifanr/:channel?', require('./routes/ifanr/index')); // 果壳网 router.get('/guokr/scientific', require('./routes/guokr/scientific')); +router.get('/guokr/:category', require('./routes/guokr/calendar')); // 联合早报 router.get('/zaobao/realtime/:type?', require('./routes/zaobao/realtime')); diff --git a/lib/routes/guokr/calendar.js b/lib/routes/guokr/calendar.js new file mode 100644 index 0000000000..bbf91bc4ba --- /dev/null +++ b/lib/routes/guokr/calendar.js @@ -0,0 +1,46 @@ +const got = require('@/utils/got'); + +async function loadFullPage(ctx, id) { + const link = `https://apis.guokr.com/minisite/article/${id}.json`; + const content = await ctx.cache.tryGet(link, async () => { + const res = await got.get(link); + return res.data.result.content; + }); + return content; +} + +const categoryMap = { + calendar: '物种日历', + institute: '吃货研究所', + beauty: '美丽也是技术活', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category; + if (categoryMap[category] === undefined) { + throw new Error(`Unknown category ${category}`); + } + + const response = await got.get(`https://www.guokr.com/${category}`); + + const rule = /(?<=