feat(route): 新增 米游社 路由 (#9404)

* feat: 优化B站动态转发内容中的图片和视频

* style: 修复格式错误

* fix: 修复 B站动态转发多图的图片缺失

* style: 整理代码格式

* style: 整理代码格式

* fix: 修复B站动态转发视频缺失标题

* fix: 移除了部分不必要的代码

* fix: 修复b站动态中转发直播间动态出现undefined;整理部分代码

* style: 整理代码格式

* fix: 补充b站动态中转发活动的信息

* fix: 修正代码格式

* fix: b站动态转发专题页缺少标题;整理部分代码

* fix: 修复图片错误

* fix: 修复专栏封面缺失的bug;增加B站动态格式总结

* style:修复格式问题

* fix: 修复/robots.txt路由

* fix

* chore: 合并冲突

* fix

* fix

* feat: 优化B站动态url

* fix: 改 \n 为<br>

* chore: 更新 npm registry

* feat: 完成 米游社路由和文档的编写

* fix: 修复 @vuepress/shared-utils 在 yarn.lock 的缺失

* chore: exact match

* fix: parseDate
This commit is contained in:
CaoMeiYouRen 2022-03-29 20:21:21 +08:00 committed by GitHub
parent 1fc9c4aa0d
commit b70e690a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 125 additions and 1 deletions

View File

@ -573,6 +573,24 @@ Example`https://www.iyingdi.com/tz/people/55547` id 是 `55547`
</Route>
### 米游社 - 官方公告
<Route author="CaoMeiYouRen" example="/mihoyo/bbs/official/2/3/20/" path="/bbs/official/:gids/:type?/:page_size?/:last_id?" :paramsDesc="['游戏id','公告类型,默认为 2(即 活动)','分页大小,默认为 20 ','跳过的公告数,例如指定为 40 就是从第 40 条公告开始,可用于分页']" radar="1">
游戏 id
| 崩坏三 | 原神 | 崩坏二 | 未定事件簿 | 星穹铁道 |
| --- | -- | --- | ----- | ---- |
| 1 | 2 | 3 | 4 | 6 |
公告类型
| 公告 | 活动 | 资讯 |
| -- | -- | -- |
| 1 | 2 | 3 |
</Route>
## 明日方舟
### 游戏公告与新闻

62
lib/v2/mihoyo/bbs.js Normal file
View File

@ -0,0 +1,62 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { parseDate } = require('@/utils/parse-date');
// 游戏id
const GITS_MAP = {
1: '崩坏三',
2: '原神',
3: '崩坏二',
4: '未定事件簿',
6: '崩坏:星穹铁道',
};
// 公告类型
const TYPE_MAP = {
1: '公告',
2: '活动',
3: '资讯',
};
const renderDescription = (description, images) => art(path.join(__dirname, 'templates/description.art'), { description, images });
module.exports = async (ctx) => {
const { gids, type = '2', page_size = '20', last_id = '' } = ctx.params;
const query = new URLSearchParams({
gids,
type,
page_size,
last_id,
}).toString();
const url = `https://bbs-api.mihoyo.com/post/wapi/getNewsList?${query}`;
const response = await got({
method: 'get',
url,
});
const list = response?.data?.data?.list;
if (!list) {
throw new Error('未获取到数据!');
}
const title = `米游社 - ${GITS_MAP[gids] || ''} - ${TYPE_MAP[type] || ''}`;
const items = list.map((e) => {
const author = e.user.nickname;
const title = e.post.subject;
const link = `https://bbs.mihoyo.com/ys/article/${e.post.post_id}`;
const description = renderDescription(e.post.content, e.post.images);
const pubDate = parseDate(e.post.created_at * 1000);
return {
author,
title,
link,
description,
pubDate,
};
});
const data = {
title,
link: url,
item: items,
};
ctx.state.data = data;
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/bbs/official/:gids/:type?/:page_size?/:last_id?': ['CaoMeiYouRen'],
};

31
lib/v2/mihoyo/radar.js Normal file
View File

@ -0,0 +1,31 @@
module.exports = {
'mihoyo.com': {
_name: '米游社v2',
bbs: [
{
title: '米游社 - 官方公告',
docs: 'https://docs.rsshub.app/game.html#mi-ha-you-mi-you-she-guan-fang-gong-gao',
// source: ['/ys/home/28', '/bh3/home/6', '/bh2/home/31', '/wd/home/33', '/sr/home/53'],
source: ['/:game/home/28', '/:game/home/6', '/:game/home/31', '/:game/home/33', '/:game/home/53'],
target: (params, url) => {
const GITS_MAP = {
bh3: 1, // '崩坏三',
ys: 2, // '原神',
bh2: 3, // '崩坏二',
wd: 4, // '未定事件簿',
sr: 6, // '崩坏:星穹铁道',
};
const { game } = params;
const gids = GITS_MAP[game];
if (!gids) {
return '';
}
const { type = '2' } = new URL(url).searchParams;
const page_size = '20';
const last_id = '';
return `/mihoyo/bbs/official/${gids}/${type}/${page_size}/${last_id}`;
},
},
],
},
};

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

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/bbs/official/:gids/:type?/:page_size?/:last_id?', require('./bbs'));
};

View File

@ -0,0 +1,6 @@
{{ description }}
{{if images}}
{{each images}}
<img src="{{ $value }}">
{{/each}}
{{/if}}

View File

@ -48,6 +48,7 @@
"@vuepress/plugin-back-to-top": "1.9.7",
"@vuepress/plugin-google-analytics": "1.9.7",
"@vuepress/plugin-pwa": "1.9.7",
"@vuepress/shared-utils": "1.9.7",
"ci-info": "3.3.0",
"cross-env": "7.0.3",
"eslint": "8.12.0",
@ -162,4 +163,4 @@
"engines": {
"node": ">=14"
}
}
}