feat(zfrontier): 增加装备前线子板块的路由 (#4147)

This commit is contained in:
c4605
2020-03-03 00:16:10 +08:00
committed by GitHub
parent f2ebdce246
commit 04fa4d1852
4 changed files with 50 additions and 0 deletions
+12
View File
@@ -977,6 +977,18 @@ Supported sub-sites:
<Route author="Jeason0228" example="/zfrontier/postlist/:byReplyTime" path="/zfrontier/postlist" :paramsDesc="['内容标签, 点击标签后地址栏有显示']"/>
### 子板块帖子
<Route author="c4605" example="/zfrontier/board/56" path="/zfrontier/board/:boardId" :paramsDesc="['板块 ID']"/>
QueryString:
- `sort`:排序方式
| 根据创建时间(默认) | 根据回复时间 | 根据热度 |
| -------------------- | ------------ | -------- |
| byCtime | byReplyTime | byScore |
## 紫竹张先生
### 全文
+1
View File
@@ -1496,6 +1496,7 @@ router.get('/manhuadb/comics/:id', require('./routes/manhuadb/comics'));
// 装备前线
router.get('/zfrontier/postlist/:type', require('./routes/zfrontier/postlist'));
router.get('/zfrontier/board/:boardId', require('./routes/zfrontier/board_postlist'));
// 观察者风闻话题
router.get('/guanchazhe/topic/:id', require('./routes/guanchazhe/topic'));
+36
View File
@@ -0,0 +1,36 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const boardId = ctx.params.boardId;
const sortType = ctx.query.sortType || 'byCtime';
const response = await got({
method: 'get',
url: `https://www.zfrontier.com/board/${boardId}?sort=${sortType}&page=1`,
});
const data = response.data;
const $ = cheerio.load(data);
const boardTitle = $('.board-head-area h1').text();
const list = $('.post-entry');
ctx.state.data = {
title: `${boardTitle} - 贴子列表 - zFrontier装备前线`,
link: response.url,
description: 'zFrontier 发烧友的最前线',
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: `${item.find('.post-title h2').text()}`,
description: `${item.find('.ellipsis').html()}<br/>${item.find('.imgs-wrap').html()}`,
link: `https://www.zfrontier.com${item.find('.post-title').attr('href')}`,
author: item.find('.author a').text(),
pubDate: new Date(item.find('.time').text()).toLocaleDateString(),
};
})
.get(),
};
};
+1
View File
@@ -24,6 +24,7 @@ module.exports = async (ctx) => {
title: `${item.find('.post-title h2').text()}`,
description: `${item.find('.ellipsis').html()}<br/>${item.find('.imgs-wrap').html()}`,
link: `https://www.zfrontier.com${item.find('.post-title').attr('href')}`,
author: item.find('.author a').text(),
pubDate: new Date(item.find('.time').text()).toLocaleDateString(),
};
})