mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 19:49:58 +00:00
Centralized management of external links (#4471)
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>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
|
||||
import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions'
|
||||
import { useSelectedLiteGraphItems } from '@/composables/canvas/useSelectedLiteGraphItems'
|
||||
import { useExternalLink } from '@/composables/useExternalLink'
|
||||
import { useModelSelectorDialog } from '@/composables/useModelSelectorDialog'
|
||||
import {
|
||||
DEFAULT_DARK_COLOR_PALETTE,
|
||||
@@ -76,6 +77,7 @@ export function useCoreCommands(): ComfyCommand[] {
|
||||
const canvasStore = useCanvasStore()
|
||||
const executionStore = useExecutionStore()
|
||||
const telemetry = useTelemetry()
|
||||
const { staticUrls, buildDocsUrl } = useExternalLink()
|
||||
|
||||
const bottomPanelStore = useBottomPanelStore()
|
||||
|
||||
@@ -761,10 +763,7 @@ export function useCoreCommands(): ComfyCommand[] {
|
||||
is_external: true,
|
||||
source: 'menu'
|
||||
})
|
||||
window.open(
|
||||
'https://github.com/comfyanonymous/ComfyUI/issues',
|
||||
'_blank'
|
||||
)
|
||||
window.open(staticUrls.githubIssues, '_blank')
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -779,7 +778,7 @@ export function useCoreCommands(): ComfyCommand[] {
|
||||
is_external: true,
|
||||
source: 'menu'
|
||||
})
|
||||
window.open('https://docs.comfy.org/', '_blank')
|
||||
window.open(buildDocsUrl('/', { includeLocale: true }), '_blank')
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -794,7 +793,7 @@ export function useCoreCommands(): ComfyCommand[] {
|
||||
is_external: true,
|
||||
source: 'menu'
|
||||
})
|
||||
window.open('https://www.comfy.org/discord', '_blank')
|
||||
window.open(staticUrls.discord, '_blank')
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -861,7 +860,7 @@ export function useCoreCommands(): ComfyCommand[] {
|
||||
is_external: true,
|
||||
source: 'menu'
|
||||
})
|
||||
window.open('https://forum.comfy.org/', '_blank')
|
||||
window.open(staticUrls.forum, '_blank')
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
99
src/composables/useExternalLink.ts
Normal file
99
src/composables/useExternalLink.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user