From e025857586960fe9ffdab01e2b7853b6c404550a Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Tue, 2 Mar 2021 14:59:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20shuax=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=20(#7025)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/program-update.md | 12 ++++++++++++ lib/router.js | 3 +++ lib/routes/shuax/project.js | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 lib/routes/shuax/project.js diff --git a/docs/program-update.md b/docs/program-update.md index 57cc140916..91114ab09a 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -354,6 +354,18 @@ pageClass: routes +## Shuax + +### Project + + + +| MouseInc | Chrome | Edge | +| -------- | ------ | ---- | +| mouseinc | chrome | edge | + + + ## simpread ### 消息通知 diff --git a/lib/router.js b/lib/router.js index c62a3af629..3a8160ab13 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3933,6 +3933,9 @@ router.get('/tianyancha/hot', require('./routes/tianyancha/hot')); // King Arthur router.get('/kingarthur/:type', require('./routes/kingarthur/index')); +// Shuax +router.get('/shuax/project/:name?', require('./routes/shuax/project')); + // BioOne router.get('/bioone/featured', require('./routes/bioone/featured')); diff --git a/lib/routes/shuax/project.js b/lib/routes/shuax/project.js new file mode 100644 index 0000000000..f38fb33aa5 --- /dev/null +++ b/lib/routes/shuax/project.js @@ -0,0 +1,37 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const name = ctx.params.name || 'mouseinc'; + + const rootUrl = 'https://shuax.com'; + const currentUrl = `${rootUrl}/project/${name}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + $('.love-box').remove(); + + const title = $('title').text(); + + ctx.state.data = { + title: `${title.split(' ')[0]} - 耍下`, + link: currentUrl, + item: [ + { + link: currentUrl, + title: title.replace(' – 耍下', ''), + description: $('#page-content').html(), + pubDate: new Date( + response.data + .match(/\d{4}年\d+月\d+日/)[0] + .replace(/年|月/g, '-') + .replace('日', '') + ).toUTCString(), + }, + ], + }; +};