feat: add 福利年 (#5638)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen 2020-09-21 04:30:24 +08:00 committed by GitHub
parent d33b4ab0e3
commit 9fb13f3147
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 0 deletions

View File

@ -627,6 +627,18 @@ area 分区选项
| ---- | ----- |
| doc | video |
## 福利年
### 文章
<Route author="nczitzk" example="/fulinian" path="/fulinian/:caty?" :paramsDesc="['分类, 默认为首页最新发布']">
| 技术教程 | 精品软件 | 网络资源 | 福利年惠 | 创业知识 | 正版教程 |
| ---------------- | ---------------- | ---------------- | -------- | -------- | ---------------- |
| technical-course | quality-software | network-resource | fulinian | chuangye | authentic-course |
</Route>
## 谷歌新闻
### 新闻

View File

@ -3216,6 +3216,9 @@ router.get('/feixuew/:id?', require('./routes/feixuew/index'));
// 1X
router.get('/1x/:type?/:caty?', require('./routes/1x/index'));
// 福利年
router.get('/fulinian/:caty?', require('./routes/fulinian/index'));
// CGTN
router.get('/cgtn/most/:type?/:time?', require('./routes/cgtn/most'));

View File

@ -0,0 +1,51 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const rootUrl = 'https://www.fulinian.com/';
module.exports = async (ctx) => {
ctx.params.caty = ctx.params.caty || '';
const currentUrl = `${rootUrl}/${ctx.params.caty}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('article.excerpt')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const a = item.find('header h2 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('article.article-content').html();
item.pubDate = new Date(content('div.article-meta span.item').eq(0).text() + ' GMT+8').toUTCString();
return item;
})
)
);
ctx.state.data = {
title: `福利年 - ${$('h1').text()}`,
link: currentUrl,
item: items,
};
};