From 3d8a7fe3ddd181475d921524a72f7108c0cd408e Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 15 Nov 2020 03:33:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E8=B4=BE=E7=9C=9F=E7=9A=84?= =?UTF-8?q?=E7=94=B5=E5=95=86108=E5=B0=86=20(#6158)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 6 +++++ lib/router.js | 3 +++ lib/routes/jiazhen108/index.js | 48 ++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 lib/routes/jiazhen108/index.js diff --git a/docs/new-media.md b/docs/new-media.md index dfa0fcbddf..87200a2065 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1673,3 +1673,9 @@ QueryString: ### 全文 + +## 贾真的电商 108 将 + +### 「108 将」实战分享 + + diff --git a/lib/router.js b/lib/router.js index eea3f5534d..e349dc2617 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3494,6 +3494,9 @@ router.get('/mitbbs/:caty?', require('./routes/mitbbs/index')); router.get('/8kcos/', require('./routes/8kcos/latest')); router.get('/8kcos/cat/:cat*', require('./routes/8kcos/cat')); +// 贾真的电商108将 +router.get('/jiazhen108', require('./routes/jiazhen108/index')); + // Instagram router.get('/instagram/:category/:key', require('./routes/instagram/index')); diff --git a/lib/routes/jiazhen108/index.js b/lib/routes/jiazhen108/index.js new file mode 100644 index 0000000000..cac928c5e4 --- /dev/null +++ b/lib/routes/jiazhen108/index.js @@ -0,0 +1,48 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'http://www.jiazhen108.com/news/'; + const response = await got({ + method: 'get', + url: rootUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('div.met-news-list ul li') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.text(), + link: a.attr('href'), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('section.met-editor').html(); + item.pubDate = new Date(content('div.info span').eq(0).text() + ' GMT+8').toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `「108将」实战分享`, + link: rootUrl, + item: items, + }; +};