feat(route): add arknights announce (#9607)

* feat: add arknights announce

* feat: dynamic rss title

* migrate arknights to v2

* fix: replace dayjs to parseDate

* refactor: sort maintainer and router

feat: add radar

refactor: use parseDate utils
This commit is contained in:
swwind 2022-04-24 23:36:14 +08:00 committed by GitHub
parent 10acacfa46
commit 29c04851da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 138 additions and 10 deletions

View File

@ -605,6 +605,24 @@ Example`https://www.iyingdi.com/tz/people/55547` id 是 `55547`
<Route author="Astrian" example="/arknights/news" path="/arknights/news"/>
### 游戏内公告
<Route author="swwind" example="/arknights/announce" path="/arknights/announce/:platform?/:group?" :paramsDesc="['平台,默认为 Android','分组,默认为 ALL']">
平台
| 安卓服 | iOS 服 | B 服 |
| :-----: | :---: | :------: |
| Android | IOS | Bilibili |
分组
| 全部 | 系统公告 | 活动公告 |
| :-: | :----: | :------: |
| ALL | SYSTEM | ACTIVITY |
</Route>
### アークナイツ (日服新闻)
<Route author="ofyark" example="/arknights/japan" path="/arknights/japan"/>

View File

@ -1856,10 +1856,10 @@ router.get('/simonsfoundation/recommend', lazyloadRouteHandler('./routes/simonsf
// 王者荣耀
router.get('/tencent/pvp/newsindex/:type', lazyloadRouteHandler('./routes/tencent/pvp/newsindex'));
// 《明日方舟》游戏
router.get('/arknights/news', lazyloadRouteHandler('./routes/arknights/news'));
// アークナイツ(明日方舟日服)
router.get('/arknights/japan', lazyloadRouteHandler('./routes/arknights/japan'));
// 《明日方舟》游戏 (migrated to v2)
// router.get('/arknights/news', lazyloadRouteHandler('./routes/arknights/news'));
// アークナイツ(明日方舟日服) (migrated to v2)
// router.get('/arknights/japan', lazyloadRouteHandler('./routes/arknights/japan'));
// 塞壬唱片
router.get('/siren/news', lazyloadRouteHandler('./routes/siren/index'));

View File

@ -0,0 +1,55 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const { platform = 'Android', group = 'ALL' } = ctx.params;
let {
data: { announceList },
} = await got({
method: 'get',
url: `https://ak-conf.hypergryph.com/config/prod/announce_meta/${platform}/announcement.meta.json`,
});
if (group !== 'ALL') {
announceList = announceList.filter((item) => item.group === group);
}
announceList = await Promise.all(
announceList.map((item) =>
ctx.cache.tryGet(item.webUrl, async () => {
const { data } = await got({
method: 'get',
url: item.webUrl,
});
const $ = cheerio.load(data);
let description =
// 一般来讲是有字的
$('.content').html() ??
// 有些情况只有一张图
$('.banner-image-container.cover').html() ??
// 有些情况啥都没有(暂时没有遇到)
'No Description';
// 游戏内部跳转链接
description = description.replace(/href="uniwebview:\/\/.+?"/, 'href="#"');
return {
title: item.title,
description,
// 不知道是哪一年的,所以不管了
pubDate: parseDate(`${item.month}-${item.day}`, 'M-D'),
link: item.webUrl,
};
})
)
);
ctx.state.data = {
title: `《明日方舟》${group === 'SYSTEM' ? '系统' : group === 'ACTIVITY' ? '活动' : '全部'}公告`,
link: 'https://ak.hypergryph.com/',
item: announceList,
};
};

View File

@ -1,4 +1,5 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const response = await got({
@ -10,7 +11,7 @@ module.exports = async (ctx) => {
const newsList = items.map((item) => ({
title: item.title,
description: item.content[0].value,
pubDate: item.publishedAt,
pubDate: parseDate(item.publishedAt),
link: `https://www.arknights.jp/news/${item.id}`,
}));

View File

@ -0,0 +1,5 @@
module.exports = {
'/announce/:platform?/:group?': ['swwind'],
'/japan': ['ofyark'],
'/news': ['Astrian'],
};

View File

@ -1,5 +1,6 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const response = await got({
@ -16,18 +17,18 @@ module.exports = async (ctx) => {
newslist
.slice(0, 9) // limit article count to a single page
.map(async (index, item) => {
const sth = $(item);
const link = `https://ak.hypergryph.com${sth.attr('href')}`;
item = $(item);
const link = `https://ak.hypergryph.com${item.attr('href')}`;
const description = await ctx.cache.tryGet(link, async () => {
const result = await got.get(link);
const result = await got(link);
const $ = cheerio.load(result.data);
return $('.article-content').html();
});
return {
title: `[${sth.find('.articleItemCate').first().text()}] ${sth.find('.articleItemTitle').first().text()}`,
title: `[${item.find('.articleItemCate').first().text()}] ${item.find('.articleItemTitle').first().text()}`,
description,
link,
pubDate: new Date(sth.find('.articleItemDate').first().text()),
pubDate: parseDate(item.find('.articleItemDate').first().text()),
};
})
.get()

40
lib/v2/arknights/radar.js Normal file
View File

@ -0,0 +1,40 @@
module.exports = {
'arknights.jp': {
_name: '明日方舟',
ak: [
{
title: 'アークナイツ(日服新闻)',
docs: 'https://docs.rsshub.app/game.html#ming-ri-fang-zhou',
source: ['/news?lang=ja&limit=9&page=1', '/'],
target: '/arknights/japan',
},
],
},
'hypergryph.com': {
_name: '明日方舟',
ak: [
{
title: '游戏公告与新闻',
docs: 'https://docs.rsshub.app/game.html#ming-ri-fang-zhou',
source: ['/news.html', '/'],
target: '/arknights/news',
},
],
'ak-conf': [
{
title: '游戏内公告',
docs: 'https://docs.rsshub.app/game.html#ming-ri-fang-zhou',
source: ['/*'],
target: '/arknights/news',
},
],
'monster-siren': [
{
title: '塞壬唱片',
docs: 'https://docs.rsshub.app/game.html#ming-ri-fang-zhou',
source: ['/info', '/'],
target: '/siren/news',
},
],
},
};

View File

@ -0,0 +1,8 @@
module.exports = function (router) {
// 《明日方舟》游戏内公告
router.get('/announce/:platform?/:group?', require('./announce'));
// アークナイツ(明日方舟日服)
router.get('/japan', require('./japan'));
// 《明日方舟》游戏公告与新闻
router.get('/news', require('./news'));
};