From e7d1a26b541f4edfde15c4abec1b26de46aed67a Mon Sep 17 00:00:00 2001 From: hoilc Date: Fri, 2 Sep 2022 00:21:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=8B=B1=E9=9B=84?= =?UTF-8?q?=E8=81=94=E7=9B=9F=E5=8F=B0=E6=9C=8D=E6=96=B0=E9=97=BB=20(#1067?= =?UTF-8?q?4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add loltw news * simplify api query --- docs/game.md | 12 ++++++++++- lib/v2/loltw/maintainer.js | 3 +++ lib/v2/loltw/news.js | 36 +++++++++++++++++++++++++++++++++ lib/v2/loltw/radar.js | 13 ++++++++++++ lib/v2/loltw/router.js | 3 +++ lib/v2/loltw/templates/news.art | 6 ++++++ 6 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 lib/v2/loltw/maintainer.js create mode 100644 lib/v2/loltw/news.js create mode 100644 lib/v2/loltw/radar.js create mode 100644 lib/v2/loltw/router.js create mode 100644 lib/v2/loltw/templates/news.art diff --git a/docs/game.md b/docs/game.md index 5f30ec9e7..c9400f742 100644 --- a/docs/game.md +++ b/docs/game.md @@ -771,7 +771,7 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` ## 英雄联盟 -### 新闻中心 +### 国服新闻 @@ -781,6 +781,16 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` +### 台服新闻 + + + +| 活动 | 资讯 | 系统 | 电竞 | 版本资讯 | 战棋资讯 | +| ----- | ---- | ------ | ------ | ----- | -------- | +| event | info | system | esport | patch | TFTpatch | + + + ## 游民星空 ### 游民星空今日推荐 diff --git a/lib/v2/loltw/maintainer.js b/lib/v2/loltw/maintainer.js new file mode 100644 index 000000000..d153028a5 --- /dev/null +++ b/lib/v2/loltw/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/news/:category?': ['hoilc'], +}; diff --git a/lib/v2/loltw/news.js b/lib/v2/loltw/news.js new file mode 100644 index 000000000..00c54d79e --- /dev/null +++ b/lib/v2/loltw/news.js @@ -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, + }; +}; diff --git a/lib/v2/loltw/radar.js b/lib/v2/loltw/radar.js new file mode 100644 index 000000000..c9613aeff --- /dev/null +++ b/lib/v2/loltw/radar.js @@ -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 || ''), + }, + ], + }, +}; diff --git a/lib/v2/loltw/router.js b/lib/v2/loltw/router.js new file mode 100644 index 000000000..dae94fc37 --- /dev/null +++ b/lib/v2/loltw/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/news/:category?', require('./news')); +}; diff --git a/lib/v2/loltw/templates/news.art b/lib/v2/loltw/templates/news.art new file mode 100644 index 000000000..d009bbd37 --- /dev/null +++ b/lib/v2/loltw/templates/news.art @@ -0,0 +1,6 @@ +
+{{if img}} + +{{/if}} +{{@ content }} +