This is an automated email from the ASF dual-hosted git repository. shuai pushed a commit to branch test in repository https://gitbox.apache.org/repos/asf/answer.git
The following commit(s) were added to refs/heads/test by this push: new 44beb6d1 fix: Optimize list type judgment logic 44beb6d1 is described below commit 44beb6d15ce0f323b38c3e5f6ed1103790e0db9e Author: shuai <lishuail...@sifou.com> AuthorDate: Wed Sep 10 14:17:26 2025 +0800 fix: Optimize list type judgment logic --- i18n/zh_CN.yaml | 1 + ui/src/pages/Tags/Detail/index.tsx | 18 ++++-------------- ui/src/utils/common.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/i18n/zh_CN.yaml b/i18n/zh_CN.yaml index 629ac11a..996cfa56 100644 --- a/i18n/zh_CN.yaml +++ b/i18n/zh_CN.yaml @@ -841,6 +841,7 @@ ui: http_50X: HTTP 错误 500 http_403: HTTP 错误 403 logout: 退出 + posts: 帖子 notifications: title: 通知 inbox: 收件箱 diff --git a/ui/src/pages/Tags/Detail/index.tsx b/ui/src/pages/Tags/Detail/index.tsx index dc475667..62ff5dd4 100644 --- a/ui/src/pages/Tags/Detail/index.tsx +++ b/ui/src/pages/Tags/Detail/index.tsx @@ -24,7 +24,6 @@ import { Link, useNavigate, useSearchParams, - useMatch, } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; @@ -39,7 +38,7 @@ import { } from '@/services'; import QuestionList, { QUESTION_ORDER_KEYS } from '@/components/QuestionList'; import HotQuestions from '@/components/HotQuestions'; -import { guard } from '@/utils'; +import { guard, pageTitleType } from '@/utils'; import { pathFactory } from '@/router/pathFactory'; const Index: FC = () => { @@ -66,8 +65,6 @@ const Index: FC = () => { tagInfo?.tag_id, tagInfo?.status, ); - const matchQuestions = useMatch('/tags/:tagName/questions'); - const matchPosts = useMatch('/tags/:tagName'); const toggleFollow = () => { if (!guard.tryNormalLogged(true)) { return; @@ -103,16 +100,9 @@ const Index: FC = () => { }, [tagResp, followResp]); let pageTitle = ''; if (tagInfo?.display_name) { - if (matchQuestions) { - pageTitle = `'${tagInfo.display_name}' ${t('questions', { - keyPrefix: 'page_title', - })}`; - } - if (matchPosts) { - pageTitle = `'${tagInfo.display_name}' ${t('posts', { - keyPrefix: 'page_title', - })}`; - } + pageTitle = `'${tagInfo.display_name}' ${t(pageTitleType(), { + keyPrefix: 'page_title', + })}`; } const keywords: string[] = []; if (tagInfo?.slug_name) { diff --git a/ui/src/utils/common.ts b/ui/src/utils/common.ts index 996da7f6..4cc78ebe 100644 --- a/ui/src/utils/common.ts +++ b/ui/src/utils/common.ts @@ -292,6 +292,17 @@ function isDarkTheme() { return htmlTag.getAttribute('data-bs-theme') === 'dark'; } +function pageTitleType() { + const { pathname } = window.location; + if (pathname.endsWith('/articles')) { + return 'articles'; + } + if (pathname.endsWith('/questions')) { + return 'questions'; + } + return 'posts'; +} + export { thousandthDivision, formatCount, @@ -310,4 +321,5 @@ export { getUaType, changeTheme, isDarkTheme, + pageTitleType, };