feat: add blizzard news (#6311)
This commit is contained in:
parent
a694450eab
commit
6d162fd3c0
|
|
@ -4,6 +4,52 @@ pageClass: routes
|
|||
|
||||
# Gaming
|
||||
|
||||
## Blizzard
|
||||
|
||||
### News
|
||||
|
||||
<RouteEn author="nczitzk" example="/blizzard/news" path="/blizzard/news/:language?/:category?" :paramsDesc="['Language code, see below, en-US by default', 'Category, see below, All News by default']">
|
||||
|
||||
Categories
|
||||
|
||||
| Category | Slug |
|
||||
| ---------------------- | ------------------- |
|
||||
| All News | |
|
||||
| Diablo III | diablo3 |
|
||||
| Diablo IV | diablo4 |
|
||||
| Diablo: Immortal | diablo-immortal |
|
||||
| Hearthstone | hearthstone |
|
||||
| Heroes of the Storm | heroes-of-the-storm |
|
||||
| Overwatch | overwatch |
|
||||
| StarCraft: Remastered | starcraft |
|
||||
| StarCraft II | starcraft2 |
|
||||
| World of Warcraft | world-of-warcraft |
|
||||
| Warcraft III: Reforged | warcraft3 |
|
||||
| BlizzCon | blizzcon |
|
||||
| Inside Blizzard | blizzard |
|
||||
|
||||
Language codes
|
||||
|
||||
| Language | Code |
|
||||
| -------------- | ----- |
|
||||
| Deutsch | de-de |
|
||||
| English (US) | en-us |
|
||||
| English (EU) | en-gb |
|
||||
| Español (EU) | es-es |
|
||||
| Español (AL) | es-mx |
|
||||
| Français | fr-fr |
|
||||
| Italiano | it-it |
|
||||
| Português (AL) | pt-br |
|
||||
| Polski | pl-pl |
|
||||
| Русский | ru-ru |
|
||||
| 한국어 | ko-kr |
|
||||
| ภาษาไทย | th-th |
|
||||
| 日本語 | ja-jp |
|
||||
| 繁體中文 | zh-tw |
|
||||
| 简体中文 | zh-cn |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## dekudeals
|
||||
|
||||
### Category
|
||||
|
|
|
|||
45
docs/game.md
45
docs/game.md
|
|
@ -40,6 +40,51 @@ pageClass: routes
|
|||
|
||||
<Route author="monner-henster" example="/a9vg/a9vg" path="/a9vg/a9vg"/>
|
||||
|
||||
## Blizzard
|
||||
|
||||
### News
|
||||
|
||||
<Route author="nczitzk" example="/blizzard/news" path="/blizzard/news/:language?/:category?" :paramsDesc="['语言代码,见下表,默认为 en-US', '分类,见下表,默认为全部新闻']">
|
||||
|
||||
分类
|
||||
|
||||
| 分类 | 分类名 |
|
||||
| -------------------- | ------------------- |
|
||||
| 所有新闻 | |
|
||||
| 暗黑破坏神 III | diablo3 |
|
||||
| 暗黑破坏神:不朽 | diablo-immortal |
|
||||
| 炉石传说 | hearthstone |
|
||||
| 风暴英雄 | heroes-of-the-storm |
|
||||
| 守望先锋 | overwatch |
|
||||
| 星际争霸:重制版 | starcraft |
|
||||
| 星际争霸 II | starcraft2 |
|
||||
| 魔兽世界 | world-of-warcraft |
|
||||
| 魔兽争霸 III:重制版 | warcraft3 |
|
||||
| 暴雪嘉年华 | blizzcon |
|
||||
| 走进暴雪 | blizzard |
|
||||
|
||||
语言代码
|
||||
|
||||
| 语言 | 语言代码 |
|
||||
| -------------- | -------- |
|
||||
| Deutsch | de-de |
|
||||
| English (US) | en-us |
|
||||
| English (EU) | en-gb |
|
||||
| Español (EU) | es-es |
|
||||
| Español (AL) | es-mx |
|
||||
| Français | fr-fr |
|
||||
| Italiano | it-it |
|
||||
| Português (AL) | pt-br |
|
||||
| Polski | pl-pl |
|
||||
| Русский | ru-ru |
|
||||
| 한국어 | ko-kr |
|
||||
| ภาษาไทย | th-th |
|
||||
| 日本語 | ja-jp |
|
||||
| 繁體中文 | zh-tw |
|
||||
| 简体中文 | zh-cn |
|
||||
|
||||
</Route>
|
||||
|
||||
## dekudeals
|
||||
|
||||
### 分类
|
||||
|
|
|
|||
|
|
@ -3517,6 +3517,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
|
|||
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
|
||||
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
|
||||
|
||||
// Blizzard
|
||||
router.get('/blizzard/news/:language?/:category?', require('./routes/blizzard/news'));
|
||||
|
||||
// DeepMind
|
||||
router.get('/deepmind/blog/:category?', require('./routes/deepmind/blog'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category || '';
|
||||
const language = ctx.params.language || 'en-us';
|
||||
|
||||
const rootUrl = `https://${language === 'zh-cn' ? 'cn.' : ''}news.blizzard.com`;
|
||||
const currentUrl = `${rootUrl}/${language}/${category}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.FeaturedArticle-text a, .ArticleListItem article a')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: `${rootUrl}${item.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.author = content('.ArticleDetail-bylineAuthor').text();
|
||||
item.description = content('.ArticleDetail-content').html();
|
||||
item.pubDate = content('.ArticleDetail-subHeadingLeft time').attr('timestamp');
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue