update useDocLink

pull/20801/head
Bowen Liang 12 months ago
parent 53d7dbefaa
commit 297df9b3ef

@ -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]

@ -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 baseDocUrl = baseUrl || officialDocBaseUrl
const locale = getLocaleOnClient()
const docLanguage = (['zh-Hans', 'ja-JP'].includes(locale) ? locale : 'en').toLowerCase()
const targetPath = (pathMap !== undefined) ? pathMap[docLanguage] || path : path
const docLanguage = getDocLanguage(locale)
const targetPath = (pathMap !== undefined) ? pathMap[locale] || path : path
return (targetPath.startsWith('/')) ? `${baseDocUrl}/${docLanguage}${targetPath}` : `${baseDocUrl}/${docLanguage}/${targetPath}`
}
}, [baseDocUrl])
}
const PRICING_PAGE_LANGUAGE: Record<string, string> = {

Loading…
Cancel
Save