feat: add 才府社区驿站帖子 (#5606)
This commit is contained in:
@@ -184,6 +184,10 @@ pageClass: routes
|
||||
|
||||
<Route author="nczitzk" example="/91ddcc/user/2377095" path="/91ddcc/user/:user" :paramsDesc="['用户ID,在 URL 可以找到']"/>
|
||||
|
||||
### 驿站帖子
|
||||
|
||||
<Route author="nczitzk" example="/91ddcc/stage/206" path="/91ddcc/stage/:stage" :paramsDesc="['驿站ID,在 URL 可以找到']"/>
|
||||
|
||||
## 电鸭社区
|
||||
|
||||
### 工作机会
|
||||
|
||||
@@ -2966,6 +2966,7 @@ router.get('/gov/shanghai/sthj', require('./routes/gov/shanghai/sthj'));
|
||||
|
||||
// 才符
|
||||
router.get('/91ddcc/user/:user', require('./routes/91ddcc/user'));
|
||||
router.get('/91ddcc/stage/:stage', require('./routes/91ddcc/stage'));
|
||||
|
||||
// BookwalkerTW热门新书
|
||||
router.get('/bookwalkertw/news', require('./routes/bookwalkertw/news'));
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const currentUrl = `https://sns.91ddcc.com/s/${ctx.params.stage}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
const list = $('div.log-box div.l-single')
|
||||
.slice(0, 5)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const a = item.find('div.word a.s-til');
|
||||
return {
|
||||
title: a.text(),
|
||||
link: `https://sns.91ddcc.com${a.attr('href')}`,
|
||||
pubDate: new Date(item.find('div.floor a.fr').text() + ' GMT+8').toUTCString(),
|
||||
author: item.find('div.floor a.fl').text(),
|
||||
};
|
||||
})
|
||||
.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('div.article-con').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('a.name').text()} - 才符`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
description: $('div.bot-info').text(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user