diff --git a/docs/new-media.md b/docs/new-media.md index 9c56d26001..3b10f5d3d1 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -431,7 +431,7 @@ Supported sub-sites: ### 果壳网专栏 - + | 物种日历 | 吃货研究所 | 美丽也是技术活 | | ------- | ---------| ------------ | | calendar | institute | beauty | diff --git a/lib/router.js b/lib/router.js index a40a2c7320..5b490bc630 100644 --- a/lib/router.js +++ b/lib/router.js @@ -752,7 +752,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('/guokr/:channel', require('./routes/guokr/calendar')); // 联合早报 router.get('/zaobao/realtime/:section?', require('./routes/zaobao/realtime')); diff --git a/lib/routes/guokr/calendar.js b/lib/routes/guokr/calendar.js index bbf91bc4ba..19e1e23a1f 100644 --- a/lib/routes/guokr/calendar.js +++ b/lib/routes/guokr/calendar.js @@ -9,23 +9,25 @@ async function loadFullPage(ctx, id) { return content; } -const categoryMap = { - calendar: '物种日历', - institute: '吃货研究所', - beauty: '美丽也是技术活', +const channelMap = { + calendar: 'pac', + institute: 'predator', + foodlab: 'predator', + pretty: 'beauty', }; module.exports = async (ctx) => { - const category = ctx.params.category; - if (categoryMap[category] === undefined) { - throw new Error(`Unknown category ${category}`); + const channel = channelMap[ctx.params.channel] ? channelMap[ctx.params.channel] : ctx.params.channel; + + const response = await got.get(`https://www.guokr.com/apis/minisite/article.json?retrieve_type=by_wx&channel_key=${channel}&offset=0&limit=10`); + const items = response.data.result; + + if (items.length === 0) { + throw 'Unknown channel'; } - const response = await got.get(`https://www.guokr.com/${category}`); - - const rule = /(?<=