From 44f5af98c131b3407c228f13f0ab94e5524d228a Mon Sep 17 00:00:00 2001 From: Howel <401738000@qq.com> Date: Tue, 14 May 2019 15:29:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E3=80=8CHpoi=20=E6=89=8B=E5=8A=9E=E7=BB=B4=E5=9F=BA=E3=80=8D?= =?UTF-8?q?=20(#2120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 新增路由 「Hpoi 手办维基」/hpoi/:category/:words * fix: delete console.log --- docs/anime.md | 12 ++++++++++++ lib/router.js | 3 +++ lib/routes/hpoi/index.js | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/routes/hpoi/index.js diff --git a/docs/anime.md b/docs/anime.md index 08bc59b2bf..f1e51af1e8 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -80,6 +80,18 @@ pageClass: routes +## Hpoi 手办维基 + +### 浏览周边 + + + +| 角色手办 | 作品手办 | +| --------- | -------- | +| charactar | works | + + + ## say 花火 ### 文章 diff --git a/lib/router.js b/lib/router.js index 26c8a39430..fbe8ff7c74 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1361,6 +1361,9 @@ router.get('/manhuadb/comics/:id', require('./routes/manhuadb/comics')); // 观察者风闻话题 router.get('/guanchazhe/topic/:id', require('./routes/guanchazhe/topic')); +// Hpoi 手办维基 +router.get('/hpoi/:category/:words', require('./routes/hpoi')); + // 通用CurseForge router.get('/curseforge/:gameid/:catagoryid/:projectid/files', require('./routes/curseforge/generalfiles')); diff --git a/lib/routes/hpoi/index.js b/lib/routes/hpoi/index.js new file mode 100644 index 0000000000..7380f3c2bd --- /dev/null +++ b/lib/routes/hpoi/index.js @@ -0,0 +1,41 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +const host = 'https://www.hpoi.net'; + +const MAPs = { + charactar: { + url: `${host}/hobby/all?charactar={words}&order=release`, + title: '角色手办', + }, + works: { + url: `${host}/hobby/all?works={words}&order=release`, + title: '作品手办', + }, +}; + +module.exports = async (ctx) => { + const category = ctx.params && ctx.params.category; + const words = ctx.params && ctx.params.words; + const response = await axios({ + method: 'get', + url: MAPs[category].url.replace(/{words}/, words), + headers: { + Referer: host, + }, + }); + const $ = cheerio.load(response.data); + ctx.state.data = { + title: MAPs[category].title + ' - ' + $('title').text(), + item: $('.bs-glyphicons-list .detail-grid') + .map((_index, _item) => { + _item = $(_item); + return { + title: _item.find('.detail-grid-title').text(), + link: host + '/' + _item.find('.detail-grid-title a').attr('href'), + description: _item.find('.detail-grid-info').text(), + }; + }) + .get(), + }; +};