mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 22:59:14 +00:00
Update the desktop guide links to make them platform and locale-aware Edited by Terry: Refactor external link management by introducing a centralized useExternalLink composable with automatic locale and platform detection for documentation URLs. - Created useExternalLink composable - A new centralized utility for managing all external links - Dynamic docs URL builder (buildDocsUrl) - Automatically constructs docs.comfy.org URLs with: - Locale detection (Chinese vs English) - Platform detection (macOS vs Windows for desktop) - Flexible path construction with options ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-4471-Add-platform-and-locale-aware-desktop-guide-URL-2346d73d3650815ea4a4dd64be575bbe) by [Unito](https://www.unito.io) --------- Co-authored-by: Terry Jia <terryjia88@gmail.com>
100 lines
2.9 KiB
TypeScript
100 lines
2.9 KiB
TypeScript
import { computed } from 'vue'
|
|
|
|
import { electronAPI, isElectron } from '@/utils/envUtil'
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
/**
|
|
* Composable for building docs.comfy.org URLs with automatic locale and platform detection
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const { buildDocsUrl } = useExternalLink()
|
|
*
|
|
* // Simple usage
|
|
* const changelogUrl = buildDocsUrl('/changelog', { includeLocale: true })
|
|
* // => 'https://docs.comfy.org/zh-CN/changelog' (if Chinese)
|
|
*
|
|
* // With platform detection
|
|
* const desktopUrl = buildDocsUrl('/installation/desktop', {
|
|
* includeLocale: true,
|
|
* platform: true
|
|
* })
|
|
* // => 'https://docs.comfy.org/zh-CN/installation/desktop/macos' (if Chinese + macOS)
|
|
* ```
|
|
*/
|
|
export function useExternalLink() {
|
|
const { locale } = useI18n()
|
|
|
|
const isChinese = computed(() => {
|
|
return locale.value === 'zh' || locale.value === 'zh-TW'
|
|
})
|
|
|
|
const platform = computed(() => {
|
|
if (!isElectron()) {
|
|
return null
|
|
}
|
|
|
|
const electronPlatform = electronAPI().getPlatform()
|
|
return electronPlatform === 'darwin' ? 'macos' : 'windows'
|
|
})
|
|
|
|
/**
|
|
* Build a docs.comfy.org URL with optional locale and platform
|
|
*
|
|
* @param path - The path after the domain (e.g., '/installation/desktop')
|
|
* @param options - Options for building the URL
|
|
* @param options.includeLocale - Whether to include locale prefix (default: false)
|
|
* @param options.platform - Whether to include platform suffix (default: false)
|
|
* @returns The complete docs URL
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* buildDocsUrl('/changelog') // => 'https://docs.comfy.org/changelog'
|
|
* buildDocsUrl('/changelog', { includeLocale: true }) // => 'https://docs.comfy.org/zh-CN/changelog' (if Chinese)
|
|
* buildDocsUrl('/installation/desktop', { includeLocale: true, platform: true })
|
|
* // => 'https://docs.comfy.org/zh-CN/installation/desktop/macos' (if Chinese + macOS)
|
|
* ```
|
|
*/
|
|
const buildDocsUrl = (
|
|
path: string,
|
|
options: {
|
|
includeLocale?: boolean
|
|
platform?: boolean
|
|
} = {}
|
|
): string => {
|
|
const { includeLocale = false, platform: includePlatform = false } = options
|
|
|
|
let url = 'https://docs.comfy.org'
|
|
|
|
if (includeLocale && isChinese.value) {
|
|
url += '/zh-CN'
|
|
}
|
|
|
|
const normalizedPath = path.startsWith('/') ? path : `/${path}`
|
|
url += normalizedPath
|
|
|
|
if (includePlatform && platform.value) {
|
|
url = url.endsWith('/') ? url : `${url}/`
|
|
url += platform.value
|
|
}
|
|
|
|
return url
|
|
}
|
|
|
|
const staticUrls = {
|
|
// Static external URLs
|
|
discord: 'https://www.comfy.org/discord',
|
|
github: 'https://github.com/comfyanonymous/ComfyUI',
|
|
githubIssues: 'https://github.com/comfyanonymous/ComfyUI/issues',
|
|
githubFrontend: 'https://github.com/Comfy-Org/ComfyUI_frontend',
|
|
githubElectron: 'https://github.com/Comfy-Org/electron',
|
|
forum: 'https://forum.comfy.org/',
|
|
comfyOrg: 'https://www.comfy.org/'
|
|
}
|
|
|
|
return {
|
|
buildDocsUrl,
|
|
staticUrls
|
|
}
|
|
}
|