From 59b2196b2836bc8a72385178baf1d8622ac3c693 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Sun, 16 Jun 2019 20:31:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20AI=E7=A0=94=E4=B9=A0=E7=A4=BE=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8F=82=E6=95=B0=20(#2416)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * enhance: AI研习社添加参数 * 支持查看不同领域 * 排序方式 * fix warning * enhance: 添加更多类别 --- docs/programming.md | 4 ++-- lib/router.js | 2 +- lib/routes/aiyanxishe/home.js | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/programming.md b/docs/programming.md index 4ed17bdfe..ba19721ec 100644 --- a/docs/programming.md +++ b/docs/programming.md @@ -6,9 +6,9 @@ pageClass: routes ## AI 研习社 -### 最新 +### 首页 - + ## AlgoCasts diff --git a/lib/router.js b/lib/router.js index 88f6788e0..dbe3c3c6c 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1419,6 +1419,6 @@ router.get('/outagereport/:name/:count?', require('./routes/outagereport/service router.get('/sixthtone/news', require('./routes/sixthtone/news')); // AI研习社 -router.get('/aiyanxishe/', require('./routes/aiyanxishe/home')); +router.get('/aiyanxishe/:id/:sort?', require('./routes/aiyanxishe/home')); module.exports = router; diff --git a/lib/routes/aiyanxishe/home.js b/lib/routes/aiyanxishe/home.js index 91a261c2f..ed1de8a38 100644 --- a/lib/routes/aiyanxishe/home.js +++ b/lib/routes/aiyanxishe/home.js @@ -1,9 +1,27 @@ const got = require('@/utils/got'); module.exports = async (ctx) => { + const id = ctx.params.id; + const sort = ctx.params.sort || 'new'; + + let url = 'https://www.leiphone.com/club/api?page=1&size=30&parent_tag='; + + if (id === 'all') { + url += '&tag='; + } else { + url += `&tag=${id}`; + } + if (sort === 'hot') { + url += '&is_hot=1&is_recommend=0'; + } else if (sort === 'recommend') { + url += '&is_hot=0&is_recommend=1'; + } else { + url += '&is_hot=0&is_recommend=0'; + } + const response = await got({ method: 'GET', - url: 'https://www.leiphone.com/club/api?page=1&size=30&is_hot=0&is_recommend=0&tag=&parent_tag=', + url: url, headers: { Referer: `https://www.leiphone.com/club/api?page=1&size=30&is_hot=0&is_recommend=0&tag=&parent_tag='`, },