feat: add 贾真的电商108将 (#6158)

This commit is contained in:
Ethan Shen
2020-11-14 19:33:08 +00:00
committed by GitHub
parent f2a0494ad5
commit 3d8a7fe3dd
3 changed files with 57 additions and 0 deletions
+6
View File
@@ -1673,3 +1673,9 @@ QueryString:
### 全文
<Route author="HenryQW" example="/zzz" path="/zzz/index"/>
## 贾真的电商 108 将
### 「108 将」实战分享
<Route author="nczitzk" example="/jiazhen108" path="/jiazhen108" />
+3
View File
@@ -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'));
+48
View File
@@ -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,
};
};