diff --git a/docs/new-media.md b/docs/new-media.md index 69245a8603..06e8aa8d85 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -194,6 +194,20 @@ pageClass: routes +## Kotaku + +### 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`填入,该路由并不会正常工作 + + + ## Krankenkassen 德国新闻社卫健新闻 ### dpa news diff --git a/lib/router.js b/lib/router.js index 4b9c03525a..732c355baa 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/kotaku/story.js b/lib/routes/kotaku/story.js new file mode 100644 index 0000000000..f008b78a32 --- /dev/null +++ b/lib/routes/kotaku/story.js @@ -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, + }; +};