diff --git a/docs/new-media.md b/docs/new-media.md index 671b8e182..9c56d2600 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -977,6 +977,18 @@ Supported sub-sites: +### 子板块帖子 + + + +QueryString: + +- `sort`:排序方式 + +| 根据创建时间(默认) | 根据回复时间 | 根据热度 | +| -------------------- | ------------ | -------- | +| byCtime | byReplyTime | byScore | + ## 紫竹张先生 ### 全文 diff --git a/lib/router.js b/lib/router.js index 8c6104d05..76dde1b08 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/zfrontier/board_postlist.js b/lib/routes/zfrontier/board_postlist.js new file mode 100644 index 000000000..ccd64c088 --- /dev/null +++ b/lib/routes/zfrontier/board_postlist.js @@ -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()}
${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(), + }; +}; diff --git a/lib/routes/zfrontier/postlist.js b/lib/routes/zfrontier/postlist.js index 563e75283..014f3f092 100644 --- a/lib/routes/zfrontier/postlist.js +++ b/lib/routes/zfrontier/postlist.js @@ -24,6 +24,7 @@ module.exports = async (ctx) => { title: `${item.find('.post-title h2').text()}`, description: `${item.find('.ellipsis').html()}
${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(), }; })