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, + }; +};