feat: add Kotaku (#5374)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
CYTMWIA
2020-08-18 21:40:02 +01:00
committed by GitHub
co-authored by Henry Wang
parent c1e38bd2fa
commit 29fe03c48c
3 changed files with 55 additions and 0 deletions
+14
View File
@@ -194,6 +194,20 @@ pageClass: routes
<Route author="xyqfer" example="/itjuzi/merge" path="/itjuzi/merge"/>
## Kotaku
### Story
<Route author="CYTMWIA" example="/kotaku/story/news" path="/kotaku/story/:type" :paramsDesc="['Story类型']">
可在 url 中找到,例如`https://kotaku.com/c/news`和`https://kotaku.com/c/kotaku-east`中的`news`和`kotaku-east`
注意,无论是`news`还是`kotaku-east`之前都有`/c/`
所以,如果您把`https://kotaku.com/latest`中的`latest`填入,该路由并不会正常工作
</Route>
## Krankenkassen 德国新闻社卫健新闻
### dpa news
+3
View File
@@ -3062,6 +3062,9 @@ router.get('/telecompaper/news/:caty/:year?/:country?/:type?/:keyword?', require
// 水木社区
router.get('/newsmth/account/:id', require('./routes/newsmth/account'));
// Kotaku
router.get('/kotaku/story/:type', require('./routes/kotaku/story'));
// 梅斯医学
router.get('/medsci/recommend', require('./routes/medsci/recommend'));
+38
View File
@@ -0,0 +1,38 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const storyUrl = `https://kotaku.com/c/${ctx.params.type}`;
const response = await got({
method: 'get',
url: storyUrl,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('article');
const itemList = list
.map((index, item) => {
item = $(item);
const titleElem = item.find('h2').first();
const dateTime = item.find('time').first().attr('datetime');
return {
title: titleElem.length === 0 ? 'Untitled' : titleElem.text(),
author: item.find('a[href*="/author/"]').last().text(),
description: item.find('p').first().text(),
link: titleElem.parent().attr('href'),
pubDate: new Date(dateTime).toUTCString(),
};
})
.get();
ctx.state.data = {
title: $('title').text(),
link: storyUrl,
language: 'en-US',
item: itemList,
};
};