diff --git a/docs/game.md b/docs/game.md index abbe05e8b1d2db..26be3619cd64d4 100644 --- a/docs/game.md +++ b/docs/game.md @@ -573,6 +573,24 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` +### 米游社 - 官方公告 + + + +游戏 id + +| 崩坏三 | 原神 | 崩坏二 | 未定事件簿 | 星穹铁道 | +| --- | -- | --- | ----- | ---- | +| 1 | 2 | 3 | 4 | 6 | + +公告类型 + +| 公告 | 活动 | 资讯 | +| -- | -- | -- | +| 1 | 2 | 3 | + + + ## 明日方舟 ### 游戏公告与新闻 diff --git a/lib/v2/mihoyo/bbs.js b/lib/v2/mihoyo/bbs.js new file mode 100644 index 00000000000000..eabd10463cc655 --- /dev/null +++ b/lib/v2/mihoyo/bbs.js @@ -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; +}; diff --git a/lib/v2/mihoyo/maintainer.js b/lib/v2/mihoyo/maintainer.js new file mode 100644 index 00000000000000..a18b6786d8d296 --- /dev/null +++ b/lib/v2/mihoyo/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/bbs/official/:gids/:type?/:page_size?/:last_id?': ['CaoMeiYouRen'], +}; diff --git a/lib/v2/mihoyo/radar.js b/lib/v2/mihoyo/radar.js new file mode 100644 index 00000000000000..f34d15a2fbd996 --- /dev/null +++ b/lib/v2/mihoyo/radar.js @@ -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}`; + }, + }, + ], + }, +}; diff --git a/lib/v2/mihoyo/router.js b/lib/v2/mihoyo/router.js new file mode 100644 index 00000000000000..b0bd1b78363b93 --- /dev/null +++ b/lib/v2/mihoyo/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/bbs/official/:gids/:type?/:page_size?/:last_id?', require('./bbs')); +}; diff --git a/lib/v2/mihoyo/templates/description.art b/lib/v2/mihoyo/templates/description.art new file mode 100644 index 00000000000000..c195aad3b68084 --- /dev/null +++ b/lib/v2/mihoyo/templates/description.art @@ -0,0 +1,6 @@ +{{ description }} +{{if images}} + {{each images}} + + {{/each}} +{{/if}} diff --git a/package.json b/package.json index 777ffb72534417..db8256921603dc 100644 --- a/package.json +++ b/package.json @@ -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.11.0", @@ -162,4 +163,4 @@ "engines": { "node": ">=14" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index 89679f36ebfa13..03d15abad713c3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14587,4 +14587,4 @@ zepto@^1.2.0: zwitch@^1.0.0: version "1.0.5" resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.5.tgz#d11d7381ffed16b742f6af7b3f223d5cd9fe9920" - integrity sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw== \ No newline at end of file + integrity sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==