mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
update
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
import type { DataSet } from '@/models/datasets'
|
import type { DataSet } from '@/models/datasets'
|
||||||
import type { RetrievalConfig } from '@/types/app'
|
import type { RetrievalConfig } from '@/types/app'
|
||||||
|
import type { DocPathWithoutLang } from '@/types/doc-paths'
|
||||||
import { render, screen } from '@testing-library/react'
|
import { render, screen } from '@testing-library/react'
|
||||||
import userEvent from '@testing-library/user-event'
|
import userEvent from '@testing-library/user-event'
|
||||||
import { IndexingType } from '@/app/components/datasets/create/step-two'
|
import { IndexingType } from '@/app/components/datasets/create/step-two'
|
||||||
@ -237,7 +238,7 @@ describe('RetrievalSection', () => {
|
|||||||
retrievalConfig={retrievalConfig}
|
retrievalConfig={retrievalConfig}
|
||||||
showMultiModalTip
|
showMultiModalTip
|
||||||
onRetrievalConfigChange={vi.fn()}
|
onRetrievalConfigChange={vi.fn()}
|
||||||
docLink={docLink as any}
|
docLink={docLink as unknown as (path?: DocPathWithoutLang) => string}
|
||||||
/>,
|
/>,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -121,7 +121,7 @@ const DocumentsHeader: FC<DocumentsHeaderProps> = ({
|
|||||||
className="flex items-center text-text-accent"
|
className="flex items-center text-text-accent"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
href={docLink('/guides/knowledge-base/integrate-knowledge-within-application')}
|
href={docLink('/use-dify/getting-started/introduction')}
|
||||||
>
|
>
|
||||||
<span>{t('list.learnMore', { ns: 'datasetDocuments' })}</span>
|
<span>{t('list.learnMore', { ns: 'datasetDocuments' })}</span>
|
||||||
<RiExternalLinkLine className="h-3 w-3" />
|
<RiExternalLinkLine className="h-3 w-3" />
|
||||||
|
|||||||
@ -102,7 +102,7 @@ const ApiBasedExtensionModal: FC<ApiBasedExtensionModalProps> = ({
|
|||||||
<div className="flex h-9 items-center justify-between text-sm font-medium text-text-primary">
|
<div className="flex h-9 items-center justify-between text-sm font-medium text-text-primary">
|
||||||
{t('apiBasedExtension.modal.apiEndpoint.title', { ns: 'common' })}
|
{t('apiBasedExtension.modal.apiEndpoint.title', { ns: 'common' })}
|
||||||
<a
|
<a
|
||||||
href={docLink('/user-guide/extension/api-based-extension/README#api-based-extension')}
|
href={docLink('/use-dify/getting-started/introduction')}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="group flex items-center text-xs font-normal text-text-accent"
|
className="group flex items-center text-xs font-normal text-text-accent"
|
||||||
|
|||||||
@ -338,52 +338,7 @@ function generateTypeDefinitions(
|
|||||||
return lines.join('\n')
|
return lines.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate redirects map for ESLint rule
|
|
||||||
* Strips language prefix from paths for use with useDocLink
|
|
||||||
*/
|
|
||||||
function generateRedirectsModule(redirects: Redirect[]): string {
|
|
||||||
const lines: string[] = [
|
|
||||||
'// GENERATE BY script',
|
|
||||||
'// DON NOT EDIT IT MANUALLY',
|
|
||||||
'//',
|
|
||||||
'// Generated from: https://raw.githubusercontent.com/langgenius/dify-docs/refs/heads/main/docs.json',
|
|
||||||
`// Generated at: ${new Date().toISOString()}`,
|
|
||||||
'',
|
|
||||||
'/** @type {Map<string, string>} */',
|
|
||||||
'export const docRedirects = new Map([',
|
|
||||||
]
|
|
||||||
|
|
||||||
// Use a map to deduplicate paths (same path in different languages)
|
|
||||||
const pathMap = new Map<string, string>()
|
|
||||||
const langPrefixRegex = /^\/(en|zh|ja|zh-hans|ja-jp)\//
|
|
||||||
|
|
||||||
for (const redirect of redirects) {
|
|
||||||
// Skip wildcard redirects
|
|
||||||
if (redirect.source.includes(':slug'))
|
|
||||||
continue
|
|
||||||
|
|
||||||
// Strip language prefix from source and destination
|
|
||||||
const sourceWithoutLang = redirect.source.replace(langPrefixRegex, '')
|
|
||||||
const destWithoutLang = redirect.destination.replace(langPrefixRegex, '')
|
|
||||||
|
|
||||||
// Only add if we haven't seen this path yet
|
|
||||||
if (!pathMap.has(sourceWithoutLang))
|
|
||||||
pathMap.set(sourceWithoutLang, destWithoutLang)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [source, dest] of pathMap) {
|
|
||||||
lines.push(` ['${source}', '${dest}'],`)
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.push('])')
|
|
||||||
lines.push('')
|
|
||||||
|
|
||||||
return lines.join('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Fetching docs.json from GitHub...')
|
console.log('Fetching docs.json from GitHub...')
|
||||||
|
|
||||||
const response = await fetch(DOCS_JSON_URL)
|
const response = await fetch(DOCS_JSON_URL)
|
||||||
@ -391,18 +346,16 @@ async function main(): Promise<void> {
|
|||||||
throw new Error(`Failed to fetch docs.json: ${response.status} ${response.statusText}`)
|
throw new Error(`Failed to fetch docs.json: ${response.status} ${response.statusText}`)
|
||||||
|
|
||||||
const docsJson = await response.json() as DocsJson
|
const docsJson = await response.json() as DocsJson
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log('Successfully fetched docs.json')
|
console.log('Successfully fetched docs.json')
|
||||||
|
|
||||||
// Extract paths from navigation
|
// Extract paths from navigation
|
||||||
const allPaths = extractPaths(docsJson.navigation)
|
const allPaths = extractPaths(docsJson.navigation)
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`Found ${allPaths.size} total paths`)
|
console.log(`Found ${allPaths.size} total paths`)
|
||||||
|
|
||||||
// Extract OpenAPI file paths from navigation for all languages
|
// Extract OpenAPI file paths from navigation for all languages
|
||||||
const openApiPaths = extractOpenAPIPaths(docsJson.navigation)
|
const openApiPaths = extractOpenAPIPaths(docsJson.navigation)
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`Found ${openApiPaths.size} OpenAPI specs to process`)
|
console.log(`Found ${openApiPaths.size} OpenAPI specs to process`)
|
||||||
|
|
||||||
// Fetch OpenAPI specs and extract API reference paths with endpoint keys
|
// Fetch OpenAPI specs and extract API reference paths with endpoint keys
|
||||||
@ -423,7 +376,6 @@ async function main(): Promise<void> {
|
|||||||
// Get file name without language prefix (e.g., "api-reference/openapi_knowledge.json")
|
// Get file name without language prefix (e.g., "api-reference/openapi_knowledge.json")
|
||||||
const fileKey = openapiPath.replace(/^(en|zh|ja)\//, '')
|
const fileKey = openapiPath.replace(/^(en|zh|ja)\//, '')
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`Fetching OpenAPI spec: ${openapiPath}`)
|
console.log(`Fetching OpenAPI spec: ${openapiPath}`)
|
||||||
const pathMap = await fetchOpenAPIAndExtractPaths(openapiPath)
|
const pathMap = await fetchOpenAPIAndExtractPaths(openapiPath)
|
||||||
endpointMapsByLang[lang].set(fileKey, pathMap)
|
endpointMapsByLang[lang].set(fileKey, pathMap)
|
||||||
@ -456,14 +408,14 @@ async function main(): Promise<void> {
|
|||||||
|
|
||||||
// Deduplicate English API paths
|
// Deduplicate English API paths
|
||||||
const uniqueEnApiPaths = [...new Set(enApiPaths)]
|
const uniqueEnApiPaths = [...new Set(enApiPaths)]
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`Extracted ${uniqueEnApiPaths.length} unique English API reference paths`)
|
console.log(`Extracted ${uniqueEnApiPaths.length} unique English API reference paths`)
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`Generated ${Object.keys(apiPathTranslations).length} API path translations`)
|
console.log(`Generated ${Object.keys(apiPathTranslations).length} API path translations`)
|
||||||
|
|
||||||
// Group by section
|
// Group by section
|
||||||
const groups = groupPathsBySection(allPaths)
|
const groups = groupPathsBySection(allPaths)
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`Grouped into ${Object.keys(groups).length} sections:`, Object.keys(groups))
|
console.log(`Grouped into ${Object.keys(groups).length} sections:`, Object.keys(groups))
|
||||||
|
|
||||||
// Generate TypeScript
|
// Generate TypeScript
|
||||||
@ -471,7 +423,7 @@ async function main(): Promise<void> {
|
|||||||
|
|
||||||
// Write to file
|
// Write to file
|
||||||
await writeFile(OUTPUT_PATH, tsContent, 'utf-8')
|
await writeFile(OUTPUT_PATH, tsContent, 'utf-8')
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.log(`Generated TypeScript types at: ${OUTPUT_PATH}`)
|
console.log(`Generated TypeScript types at: ${OUTPUT_PATH}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user