From 36ca01429c9f46f868b4afd9c3b9c863fbb880be Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 8 Dec 2020 19:24:32 +0800 Subject: [PATCH] feat: add lowendtalk discussion (#6380) --- docs/bbs.md | 6 +++++ docs/en/bbs.md | 6 +++++ lib/router.js | 3 +++ lib/routes/lowendtalk/discussion.js | 36 +++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 lib/routes/lowendtalk/discussion.js diff --git a/docs/bbs.md b/docs/bbs.md index 102baf2d40..8396177612 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -108,6 +108,12 @@ pageClass: routes | ---- | ------------ | ---- | ----- | | jobs | translations | qa | links | +## LowEndTalk + +### Discussion + + + ## MCBBS ### 版块 diff --git a/docs/en/bbs.md b/docs/en/bbs.md index f6b29af101..953bb97a18 100644 --- a/docs/en/bbs.md +++ b/docs/en/bbs.md @@ -29,3 +29,9 @@ pageClass: routes | x | 7 | + +## LowEndTalk + +### Discussion + + diff --git a/lib/router.js b/lib/router.js index 85df4db4cf..2596e85f0e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3661,6 +3661,9 @@ router.get('/tesla', require('./routes/tesla/update')); // 复旦大学继续教育学院 router.get('/fudan/cce', require('./routes/universities/fudan/cce')); +// LowEndTalk +router.get('/lowendtalk/discussion/:id?', require('./routes/lowendtalk/discussion')); + // 无产者评论 router.get('/proletar/:type?/:id?', require('./routes/proletar/index')); diff --git a/lib/routes/lowendtalk/discussion.js b/lib/routes/lowendtalk/discussion.js new file mode 100644 index 0000000000..f0f7c563d5 --- /dev/null +++ b/lib/routes/lowendtalk/discussion.js @@ -0,0 +1,36 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.lowendtalk.com'; + const currentUrl = `${rootUrl}/discussion/${ctx.params.id}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const items = $('.userContent') + .map((_, item) => { + item = $(item); + + const header = item.parent().parent().prev(); + const pubDate = header.find('time'); + + return { + description: item.html(), + pubDate: pubDate.attr('datetime'), + author: header.find('.Author').text(), + link: `${rootUrl}${pubDate.parent().attr('href')}`, + title: `${header.find('.Author').text().trim()}: ${item.text()}`, + }; + }) + .get(); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};