feat: better format for hpoi

This commit is contained in:
DIYgod 2019-05-14 15:51:03 +08:00
parent 6a9ba55d2e
commit 57d825d156
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
2 changed files with 22 additions and 5 deletions

View File

@ -84,7 +84,7 @@ pageClass: routes
### 浏览周边
<Route author="howel52" path="/hpoi/:category/:words" example="/hpoi/charactar/1246512" :paramsDesc="['分类, 见下表', '关键词']">
<Route author="howel52 DIYgod" path="/hpoi/:category/:words" example="/hpoi/charactar/1246512" :paramsDesc="['分类, 见下表', '关键词']">
| 角色手办 | 作品手办 |
| --------- | -------- |

View File

@ -17,25 +17,42 @@ const MAPs = {
module.exports = async (ctx) => {
const category = ctx.params && ctx.params.category;
const words = ctx.params && ctx.params.words;
const link = MAPs[category].url.replace(/{words}/, words);
const response = await axios({
method: 'get',
url: MAPs[category].url.replace(/{words}/, words),
url: link,
headers: {
Referer: host,
},
});
const $ = cheerio.load(response.data);
ctx.state.data = {
title: MAPs[category].title + ' - ' + $('title').text(),
title:
'Hpoi 手办维基' +
' - ' +
$(`#${category}`)
.text()
.trim(),
link: link,
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(),
description: `<img referrerpolicy="no-referrer" src="${_item.find('.thumbnail img').attr('src')}">${_item
.find('.detail-grid-info span')
.eq(0)
.text()}<br>${_item
.find('.detail-grid-info span')
.eq(1)
.text()}<br>${_item
.find('.detail-grid-info span')
.eq(2)
.text()}`,
};
})
.get(),
.get()
.reverse(),
};
};