feat(route): add 英雄联盟台服新闻 (#10674)

* add loltw news

* simplify api query
This commit is contained in:
hoilc 2022-09-02 00:21:07 +08:00 committed by GitHub
parent 173c4e6970
commit e7d1a26b54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 1 deletions

View File

@ -771,7 +771,7 @@ Example`https://www.iyingdi.com/tz/people/55547` id 是 `55547`
## 英雄联盟
### 新闻中心
### 国服新闻
<Route author="Jeason0228" example="/lol/newsindex/all" path="/lol/newsindex/:type" :paramsDesc="['栏目分类,见下表']">
@ -781,6 +781,16 @@ Example`https://www.iyingdi.com/tz/people/55547` id 是 `55547`
</Route>
### 台服新闻
<Route author="hoilc" example="/loltw/news" path="/loltw/news/:category?" :paramsDesc="['新闻分类,置空为全部新闻']" radar="1" rssbud="1">
| 活动 | 资讯 | 系统 | 电竞 | 版本资讯 | 战棋资讯 |
| ----- | ---- | ------ | ------ | ----- | -------- |
| event | info | system | esport | patch | TFTpatch |
</Route>
## 游民星空
### 游民星空今日推荐

View File

@ -0,0 +1,3 @@
module.exports = {
'/news/:category?': ['hoilc'],
};

36
lib/v2/loltw/news.js Normal file
View File

@ -0,0 +1,36 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const category = ctx.params.category ?? '';
const baseUrl = 'https://lol.garena.tw';
const response = await got(`${baseUrl}/api/news/search?category=${category}`);
const list = response.data.data.news.map((item) => ({
guid: item.id,
title: item.title,
author: 'Garena',
link: `${baseUrl}/news/articles/${item.id}`,
pubDate: parseDate(item.updated_at * 1000),
}));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got(`${baseUrl}/api/news/detail?news_id=${item.guid}`);
item.description = art(path.join(__dirname, 'templates/news.art'), detailResponse.data.data.news_detail);
return item;
})
)
);
ctx.state.data = {
title: '英雄联盟 - 台服新闻',
link: category ? `${baseUrl}/news/${category}` : `${baseUrl}/news`,
item: items,
};
};

13
lib/v2/loltw/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'garena.tw': {
_name: 'Garena',
lol: [
{
title: '英雄联盟台服新闻',
docs: 'https://docs.rsshub.app/game.html#ying-xiong-lian-meng-tai-fu-xin-wen',
source: ['/news/:category', '/news'],
target: (params) => '/loltw/news/' + (params.category || ''),
},
],
},
};

3
lib/v2/loltw/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/news/:category?', require('./news'));
};

View File

@ -0,0 +1,6 @@
<div>
{{if img}}
<img style="max-width: 100%" src="{{ img }}">
{{/if}}
{{@ content }}
</div>