From eb6896f20fa6217322b14a28a901ac043095d42d Mon Sep 17 00:00:00 2001
From: CaoMeiYouRen <40430746+CaoMeiYouRen@users.noreply.github.com>
Date: Fri, 9 Feb 2024 21:14:05 +0800
Subject: [PATCH] =?UTF-8?q?fix(route):=20Fix=20the=20issue=20of=20missing?=
=?UTF-8?q?=20post=20cover=20in=20the=20official=20routing=20of=20Miyoushe?=
=?UTF-8?q?;=20Optimize=20the=20data=20processing=20of=20posts=20|=20?=
=?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E7=B1=B3=E6=B8=B8=E7=A4=BE=E5=AE=98?=
=?UTF-8?q?=E6=96=B9=E8=B7=AF=E7=94=B1=E4=B8=AD=E5=B8=96=E5=AD=90=E5=B0=81?=
=?UTF-8?q?=E9=9D=A2=E7=BC=BA=E5=A4=B1=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B?=
=?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B8=96=E5=AD=90=E7=9A=84=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E5=A4=84=E7=90=86=20(#14436)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat(route): 增加 米游社 - 用户关注动态 路由
* fix(route): 修复 路由、文档的风格问题
* docs: fix envs
* fix(route): 修复 米游社官方路由中帖子封面缺失的问题;优化帖子的数据处理
---------
---
lib/v2/mihoyo/bbs/img-ranking.js | 33 ++---------------------------
lib/v2/mihoyo/bbs/official.js | 21 ++----------------
lib/v2/mihoyo/bbs/timeline.js | 33 ++---------------------------
lib/v2/mihoyo/bbs/user-post.js | 33 ++---------------------------
lib/v2/mihoyo/bbs/utils.js | 34 ++++++++++++++++++++++++++++++
website/docs/routes/government.mdx | 4 ++--
website/docs/routes/other.mdx | 2 +-
7 files changed, 45 insertions(+), 115 deletions(-)
create mode 100644 lib/v2/mihoyo/bbs/utils.js
diff --git a/lib/v2/mihoyo/bbs/img-ranking.js b/lib/v2/mihoyo/bbs/img-ranking.js
index 6d988b7f9..e2a3dd51a 100644
--- a/lib/v2/mihoyo/bbs/img-ranking.js
+++ b/lib/v2/mihoyo/bbs/img-ranking.js
@@ -1,10 +1,6 @@
const got = require('@/utils/got');
-const { art } = require('@/utils/render');
-const path = require('path');
-const { parseDate } = require('@/utils/parse-date');
const { DATA_MAP, RANKING_TYPE_MAP } = require('./static-data');
-
-const renderDescription = (description, images) => art(path.join(__dirname, '../templates/description.art'), { description, images });
+const { post2item } = require('./utils');
const getGameInfo = (game) => ({
gids: DATA_MAP[game]?.gids,
@@ -75,32 +71,7 @@ module.exports = async (ctx) => {
throw new Error('未获取到数据!');
}
const title = `米游社-${game_title}-${forum_title}${cate_title ? `-${cate_title}` : ''}-${type_title}`;
- const items = list.map((e) => {
- const author = e.user.nickname;
- const title = e.post.subject;
- const link = `https://www.miyoushe.com/ys/article/${e.post.post_id}`;
- let describe = e.post.content || '';
- try {
- describe = JSON.parse(e.post.content).describe;
- } catch (error) {
- if (!(error instanceof SyntaxError)) {
- throw error;
- }
- }
- const description = renderDescription(describe || '', [...new Set([e.post.cover, ...e.post.images])].filter(Boolean));
- const pubDate = parseDate(e.post.created_at * 1000);
- const upvotes = e.stat.like_num;
- const comments = e.stat.reply_num;
- return {
- author,
- title,
- link,
- description,
- pubDate,
- upvotes,
- comments,
- };
- });
+ const items = list.map((e) => post2item(e));
const data = {
title,
link: url,
diff --git a/lib/v2/mihoyo/bbs/official.js b/lib/v2/mihoyo/bbs/official.js
index 00639fd6f..9e38ea88b 100644
--- a/lib/v2/mihoyo/bbs/official.js
+++ b/lib/v2/mihoyo/bbs/official.js
@@ -1,7 +1,5 @@
const got = require('@/utils/got');
-const { art } = require('@/utils/render');
-const path = require('path');
-const { parseDate } = require('@/utils/parse-date');
+const { post2item } = require('./utils');
// 游戏id
const GITS_MAP = {
1: '崩坏三',
@@ -19,8 +17,6 @@ const TYPE_MAP = {
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({
@@ -39,20 +35,7 @@ module.exports = async (ctx) => {
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://www.miyoushe.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 items = list.map((e) => post2item(e));
const data = {
title,
link: url,
diff --git a/lib/v2/mihoyo/bbs/timeline.js b/lib/v2/mihoyo/bbs/timeline.js
index 6c2b508ce..3c7e84fc0 100644
--- a/lib/v2/mihoyo/bbs/timeline.js
+++ b/lib/v2/mihoyo/bbs/timeline.js
@@ -1,11 +1,7 @@
const got = require('@/utils/got');
-const { art } = require('@/utils/render');
-const path = require('path');
-const { parseDate } = require('@/utils/parse-date');
const cache = require('./cache');
const config = require('@/config').value;
-
-const renderDescription = (description, images) => art(path.join(__dirname, '../templates/description.art'), { description, images });
+const { post2item } = require('./utils');
module.exports = async (ctx) => {
if (!config.mihoyo.cookie) {
@@ -34,32 +30,7 @@ module.exports = async (ctx) => {
}
const { nickname: username } = await cache.getUserFullInfo(ctx, '');
const title = `米游社 - ${username} 的关注动态`;
- const items = list.map((e) => {
- const author = e.user.nickname;
- const title = e.post.subject;
- const link = `https://www.miyoushe.com/ys/article/${e.post.post_id}`;
- let describe = e.post.content || '';
- try {
- describe = JSON.parse(e.post.content).describe;
- } catch (error) {
- if (!(error instanceof SyntaxError)) {
- throw error;
- }
- }
- const description = renderDescription(describe || '', [...new Set([e.post.cover, ...e.post.images])].filter(Boolean));
- const pubDate = parseDate(e.post.created_at * 1000);
- const upvotes = e.stat.like_num;
- const comments = e.stat.reply_num;
- return {
- author,
- title,
- link,
- description,
- pubDate,
- upvotes,
- comments,
- };
- });
+ const items = list.map((e) => post2item(e));
const data = {
title,
diff --git a/lib/v2/mihoyo/bbs/user-post.js b/lib/v2/mihoyo/bbs/user-post.js
index c68302ae3..547ff0fa3 100644
--- a/lib/v2/mihoyo/bbs/user-post.js
+++ b/lib/v2/mihoyo/bbs/user-post.js
@@ -1,9 +1,5 @@
const got = require('@/utils/got');
-const { art } = require('@/utils/render');
-const path = require('path');
-const { parseDate } = require('@/utils/parse-date');
-
-const renderDescription = (description, images) => art(path.join(__dirname, '../templates/description.art'), { description, images });
+const { post2item } = require('./utils');
module.exports = async (ctx) => {
const { uid } = ctx.params;
@@ -25,32 +21,7 @@ module.exports = async (ctx) => {
}
const username = list[0]?.user.nickname;
const title = `米游社 - ${username} 的发帖`;
- const items = list.map((e) => {
- const author = e.user.nickname;
- const title = e.post.subject;
- const link = `https://www.miyoushe.com/ys/article/${e.post.post_id}`;
- let describe = e.post.content || '';
- try {
- describe = JSON.parse(e.post.content).describe;
- } catch (error) {
- if (!(error instanceof SyntaxError)) {
- throw error;
- }
- }
- const description = renderDescription(describe || '', [...new Set([e.post.cover, ...e.post.images])].filter(Boolean));
- const pubDate = parseDate(e.post.created_at * 1000);
- const upvotes = e.stat.like_num;
- const comments = e.stat.reply_num;
- return {
- author,
- title,
- link,
- description,
- pubDate,
- upvotes,
- comments,
- };
- });
+ const items = list.map((e) => post2item(e));
const data = {
title,
diff --git a/lib/v2/mihoyo/bbs/utils.js b/lib/v2/mihoyo/bbs/utils.js
new file mode 100644
index 000000000..165d8fdd0
--- /dev/null
+++ b/lib/v2/mihoyo/bbs/utils.js
@@ -0,0 +1,34 @@
+const { art } = require('@/utils/render');
+const path = require('path');
+const { parseDate } = require('@/utils/parse-date');
+
+const renderDescription = (description, images) => art(path.join(__dirname, '../templates/description.art'), { description, images });
+
+module.exports = {
+ post2item(e) {
+ const author = e.user.nickname;
+ const title = e.post.subject;
+ const link = `https://www.miyoushe.com/ys/article/${e.post.post_id}`;
+ let describe = e.post.content || '';
+ try {
+ describe = JSON.parse(e.post.content).describe;
+ } catch (error) {
+ if (!(error instanceof SyntaxError)) {
+ throw error;
+ }
+ }
+ const description = renderDescription(describe || '', [...new Set([e.post.cover, ...e.post.images])].filter(Boolean));
+ const pubDate = parseDate(e.post.created_at * 1000);
+ const upvotes = e.stat.like_num;
+ const comments = e.stat.reply_num;
+ return {
+ author,
+ title,
+ link,
+ description,
+ pubDate,
+ upvotes,
+ comments,
+ };
+ },
+};
diff --git a/website/docs/routes/government.mdx b/website/docs/routes/government.mdx
index 71ca7b15e..da920cce8 100644
--- a/website/docs/routes/government.mdx
+++ b/website/docs/routes/government.mdx
@@ -12,9 +12,9 @@
-## Constitutional Court of Baden-Württemberg (Germany) {#constitutional-court-of-baden-w%C3%BCrttemberg-germany}
+## Constitutional Court of Baden-Württemberg (Germany) {#constitutional-court-of-baden-wvrttemberg-germany}
-### Press releases {#constitutional-court-of-baden-w%C3%BCrttemberg-germany-press-releases}
+### Press releases {#constitutional-court-of-baden-wvrttemberg-germany-press-releases}
diff --git a/website/docs/routes/other.mdx b/website/docs/routes/other.mdx
index abca26609..c69791094 100644
--- a/website/docs/routes/other.mdx
+++ b/website/docs/routes/other.mdx
@@ -121,7 +121,7 @@ See [#app-store-mac-app-store](/routes/program-update#app-store-mac-app-store)
-### Macao Pagina Electrónica Especial Contra Epidemias: What’s New {#corona-virus-disease-2019-macao-pagina-electr%C3%B3nica-especial-contra-epidemias-what-s-new}
+### Macao Pagina Electrónica Especial Contra Epidemias: What’s New {#corona-virus-disease-2019-macao-pagina-electronica-especial-contra-epidemias-what-s-new}
Official Website: [https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx](https://www.ssm.gov.mo/apps1/PreventWuhanInfection/en.aspx)