From 04fa4d1852b259083e8f4ed845df40953e413766 Mon Sep 17 00:00:00 2001 From: c4605 Date: Tue, 3 Mar 2020 00:16:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(zfrontier):=20=E5=A2=9E=E5=8A=A0=E8=A3=85?= =?UTF-8?q?=E5=A4=87=E5=89=8D=E7=BA=BF=E5=AD=90=E6=9D=BF=E5=9D=97=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=20(#4147)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 12 +++++++++ lib/router.js | 1 + lib/routes/zfrontier/board_postlist.js | 36 ++++++++++++++++++++++++++ lib/routes/zfrontier/postlist.js | 1 + 4 files changed, 50 insertions(+) create mode 100644 lib/routes/zfrontier/board_postlist.js 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(), }; })