From 297df9b3ef66a06dddc580e147612c0d937ed7c4 Mon Sep 17 00:00:00 2001 From: Bowen Liang Date: Mon, 9 Jun 2025 14:23:42 +0800 Subject: [PATCH] update useDocLink --- .../components/app/create-app-modal/index.tsx | 6 ++---- web/i18n/language.ts | 19 ++++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/web/app/components/app/create-app-modal/index.tsx b/web/app/components/app/create-app-modal/index.tsx index 834bea5cc9..662d550f04 100644 --- a/web/app/components/app/create-app-modal/index.tsx +++ b/web/app/components/app/create-app-modal/index.tsx @@ -325,14 +325,12 @@ function AppPreview({ mode }: { mode: AppMode }) { title: t('app.newApp.completeApp'), description: t('app.newApp.completionUserDescription'), link: docLink('/guides/application-orchestrate/text-generator', - { 'zh-hans': '/guides/application-orchestrate/readme' }), + { 'zh-Hans': '/guides/application-orchestrate/readme' }), }, 'workflow': { title: t('app.types.workflow'), description: t('app.newApp.workflowUserDescription'), - link: docLink('/guides/workflow/README', { - 'zh-hans': '/guides/workflow/readme', - }), + link: docLink('/guides/workflow/readme'), }, } const previewInfo = modeToPreviewInfoMap[mode] diff --git a/web/i18n/language.ts b/web/i18n/language.ts index ab1871185d..1e93884040 100644 --- a/web/i18n/language.ts +++ b/web/i18n/language.ts @@ -1,5 +1,4 @@ import data from './languages.json' -import { useMemo } from 'react' import { getLocaleOnClient } from '@/i18n/index' export type Item = { value: number | string @@ -51,17 +50,15 @@ export const getDocLanguage = (locale: string) => { return DOC_LANGUAGE[locale] || 'en' } +const officialDocBaseUrl = 'https://docs.dify.ai' export const useDocLink = (baseUrl?: string): ((path: string, pathMap?: { [index: string]: string }) => string) => { - const baseDocUrl = baseUrl || 'https://docs.dify.ai' - return useMemo(() => { - // 返回拼接函数 - return (path: string, pathMap?: { [index: string]: string }): string => { - const locale = getLocaleOnClient() - const docLanguage = (['zh-Hans', 'ja-JP'].includes(locale) ? locale : 'en').toLowerCase() - const targetPath = (pathMap !== undefined) ? pathMap[docLanguage] || path : path - return (targetPath.startsWith('/')) ? `${baseDocUrl}/${docLanguage}${targetPath}` : `${baseDocUrl}/${docLanguage}/${targetPath}` - } - }, [baseDocUrl]) + return (path: string, pathMap?: { [index: string]: string }): string => { + const baseDocUrl = baseUrl || officialDocBaseUrl + const locale = getLocaleOnClient() + const docLanguage = getDocLanguage(locale) + const targetPath = (pathMap !== undefined) ? pathMap[locale] || path : path + return (targetPath.startsWith('/')) ? `${baseDocUrl}/${docLanguage}${targetPath}` : `${baseDocUrl}/${docLanguage}/${targetPath}` + } } const PRICING_PAGE_LANGUAGE: Record = {