feat: add topys category (#2464)

This commit is contained in:
Cloud
2019-06-24 22:36:56 +08:00
committed by DIYgod
parent 72a149b03a
commit ff7a771fa6
3 changed files with 65 additions and 0 deletions

View File

@@ -205,6 +205,12 @@ pageClass: routes
</Route>
## TOPYS
### 分类
<Route author="kt286" example="/topys/7" path="/topys/:category" :paramsDesc="['分类ID可在对应页面的 URL 中找到']"/>
## TSSstatusiOS 降级通道)
### Status

View File

@@ -1427,6 +1427,9 @@ router.get('/aiyanxishe/:id/:sort?', require('./routes/aiyanxishe/home'));
// 飞客茶馆优惠信息
router.get('/flyertea/preferential', require('./routes/flyertea/preferential'));
// TOPYS
router.get('/topys/:category', require('./routes/topys/article'));
// 巴比特作者专栏
router.get('/8btc/:authorid', require('./routes/8btc/author'));

View File

@@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category;
const html = await got({
method: 'get',
url: `https://www.topys.cn/category/${category}.html`,
headers: {
referer: `https://www.topys.cn/category/${category}.html`,
cookie: 'PHPSESSID=8gd6q9j2h0o6fpsl570ah3chg8; can_webp=true',
},
});
const $ = cheerio.load(html.data);
const response = await got({
method: 'post',
url: 'https://www.topys.cn/ajax/article/get_article_list',
form: true,
data: {
needloginpage: 2,
islogin: 0,
module: 'article',
column: category,
timestape: $('#login-vue').attr('data-timestape'),
token: $('#login-vue').attr('data-token'),
offset: 0,
size: 12,
page: 0,
type: 'column',
need_count: true,
},
headers: {
referer: `https://www.topys.cn/category/${category}.html`,
cookie: 'PHPSESSID=8gd6q9j2h0o6fpsl570ah3chg8; can_webp=true',
},
});
const items = response.data.result.map((item) => {
const single = {
title: item.title,
description: item.content,
pubDate: new Date(item.app_push_time + '000').toUTCString(),
link: `http://www.topys.cn/article/detail?id=${item.id}`,
author: item.editor,
};
return single;
});
ctx.state.data = {
title: 'TOPYS | 全球顶尖创意分享平台 OPEN YOUR MIND',
link: `https://www.topys.cn/category/${category}.html`,
description: 'TOPYS | 全球顶尖创意分享平台 OPEN YOUR MIND',
item: items,
};
};