Skip to content

Commit b347dd1

Browse files
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>
1 parent 1a6913c commit b347dd1

File tree

17 files changed

+361
-83
lines changed

17 files changed

+361
-83
lines changed

src/components/dialog/content/ApiNodesSignInContent.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
import Button from 'primevue/button'
3030
import { useI18n } from 'vue-i18n'
3131
32+
import { useExternalLink } from '@/composables/useExternalLink'
33+
3234
const { t } = useI18n()
35+
const { buildDocsUrl } = useExternalLink()
3336
3437
const { apiNodeNames, onLogin, onCancel } = defineProps<{
3538
apiNodeNames: string[]
@@ -38,6 +41,9 @@ const { apiNodeNames, onLogin, onCancel } = defineProps<{
3841
}>()
3942
4043
const handleLearnMoreClick = () => {
41-
window.open('https://docs.comfy.org/tutorials/api-nodes/faq', '_blank')
44+
window.open(
45+
buildDocsUrl('/tutorials/api-nodes/faq', { includeLocale: true }),
46+
'_blank'
47+
)
4248
}
4349
</script>

src/components/dialog/content/setting/CreditsPanel.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ import { computed, ref, watch } from 'vue'
123123
import UserCredit from '@/components/common/UserCredit.vue'
124124
import UsageLogsTable from '@/components/dialog/content/setting/UsageLogsTable.vue'
125125
import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions'
126+
import { useExternalLink } from '@/composables/useExternalLink'
126127
import { useSubscription } from '@/platform/cloud/subscription/composables/useSubscription'
127128
import { useTelemetry } from '@/platform/telemetry'
128129
import { useDialogService } from '@/services/dialogService'
@@ -137,6 +138,7 @@ interface CreditHistoryItemData {
137138
isPositive: boolean
138139
}
139140
141+
const { buildDocsUrl } = useExternalLink()
140142
const dialogService = useDialogService()
141143
const authStore = useFirebaseAuthStore()
142144
const authActions = useFirebaseAuthActions()
@@ -183,12 +185,17 @@ const handleMessageSupport = async () => {
183185
}
184186
185187
const handleFaqClick = () => {
186-
window.open('https://docs.comfy.org/tutorials/api-nodes/faq', '_blank')
188+
window.open(
189+
buildDocsUrl('/tutorials/api-nodes/faq', { includeLocale: true }),
190+
'_blank'
191+
)
187192
}
188193
189194
const handleOpenPartnerNodesInfo = () => {
190195
window.open(
191-
'https://docs.comfy.org/tutorials/api-nodes/overview#api-nodes',
196+
buildDocsUrl('/tutorials/api-nodes/overview#api-nodes', {
197+
includeLocale: true
198+
}),
192199
'_blank'
193200
)
194201
}

src/components/helpcenter/HelpCenterMenuContent.vue

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ import type { CSSProperties, Component } from 'vue'
143143
import { useI18n } from 'vue-i18n'
144144
145145
import PuzzleIcon from '@/components/icons/PuzzleIcon.vue'
146+
import { useExternalLink } from '@/composables/useExternalLink'
146147
import { isCloud } from '@/platform/distribution/types'
147148
import { useSettingStore } from '@/platform/settings/settingStore'
148149
import { useTelemetry } from '@/platform/telemetry'
@@ -168,15 +169,6 @@ interface MenuItem {
168169
}
169170
170171
// Constants
171-
const EXTERNAL_LINKS = {
172-
DOCS: 'https://docs.comfy.org/',
173-
DISCORD: 'https://www.comfy.org/discord',
174-
GITHUB: 'https://github.com/comfyanonymous/ComfyUI',
175-
DESKTOP_GUIDE_WINDOWS: 'https://docs.comfy.org/installation/desktop/windows',
176-
DESKTOP_GUIDE_MACOS: 'https://docs.comfy.org/installation/desktop/macos',
177-
UPDATE_GUIDE: 'https://docs.comfy.org/installation/update_comfyui'
178-
} as const
179-
180172
const TIME_UNITS = {
181173
MINUTE: 60 * 1000,
182174
HOUR: 60 * 60 * 1000,
@@ -193,7 +185,8 @@ const SUBMENU_CONFIG = {
193185
} as const
194186
195187
// Composables
196-
const { t, locale } = useI18n()
188+
const { t } = useI18n()
189+
const { staticUrls, buildDocsUrl } = useExternalLink()
197190
const releaseStore = useReleaseStore()
198191
const commandStore = useCommandStore()
199192
const settingStore = useSettingStore()
@@ -230,11 +223,12 @@ const moreItems = computed<MenuItem[]>(() => {
230223
visible: isElectron(),
231224
action: () => {
232225
trackResourceClick('docs', true)
233-
const docsUrl =
234-
electronAPI().getPlatform() === 'darwin'
235-
? EXTERNAL_LINKS.DESKTOP_GUIDE_MACOS
236-
: EXTERNAL_LINKS.DESKTOP_GUIDE_WINDOWS
237-
openExternalLink(docsUrl)
226+
openExternalLink(
227+
buildDocsUrl('/installation/desktop', {
228+
includeLocale: true,
229+
platform: true
230+
})
231+
)
238232
emit('close')
239233
}
240234
},
@@ -286,7 +280,7 @@ const menuItems = computed<MenuItem[]>(() => {
286280
label: t('helpCenter.docs'),
287281
action: () => {
288282
trackResourceClick('docs', true)
289-
openExternalLink(EXTERNAL_LINKS.DOCS)
283+
openExternalLink(buildDocsUrl('/', { includeLocale: true }))
290284
emit('close')
291285
}
292286
},
@@ -297,7 +291,7 @@ const menuItems = computed<MenuItem[]>(() => {
297291
label: 'Discord',
298292
action: () => {
299293
trackResourceClick('discord', true)
300-
openExternalLink(EXTERNAL_LINKS.DISCORD)
294+
openExternalLink(staticUrls.discord)
301295
emit('close')
302296
}
303297
},
@@ -308,7 +302,7 @@ const menuItems = computed<MenuItem[]>(() => {
308302
label: t('helpCenter.github'),
309303
action: () => {
310304
trackResourceClick('github', true)
311-
openExternalLink(EXTERNAL_LINKS.GITHUB)
305+
openExternalLink(staticUrls.github)
312306
emit('close')
313307
}
314308
},
@@ -533,25 +527,19 @@ const onReleaseClick = (release: ReleaseNote): void => {
533527
trackResourceClick('release_notes', true)
534528
void releaseStore.handleShowChangelog(release.version)
535529
const versionAnchor = formatVersionAnchor(release.version)
536-
const changelogUrl = `${getChangelogUrl()}#${versionAnchor}`
530+
const changelogUrl = `${buildDocsUrl('/changelog', { includeLocale: true })}#${versionAnchor}`
537531
openExternalLink(changelogUrl)
538532
emit('close')
539533
}
540534
541535
const onUpdate = (_: ReleaseNote): void => {
542536
trackResourceClick('docs', true)
543-
openExternalLink(EXTERNAL_LINKS.UPDATE_GUIDE)
537+
openExternalLink(
538+
buildDocsUrl('/installation/update_comfyui', { includeLocale: true })
539+
)
544540
emit('close')
545541
}
546542
547-
// Generate language-aware changelog URL
548-
const getChangelogUrl = (): string => {
549-
const isChineseLocale = locale.value === 'zh'
550-
return isChineseLocale
551-
? 'https://docs.comfy.org/zh-CN/changelog'
552-
: 'https://docs.comfy.org/changelog'
553-
}
554-
555543
// Lifecycle
556544
onMounted(async () => {
557545
telemetry?.trackHelpCenterOpened({ source: 'sidebar' })

src/components/topbar/CurrentUserPopover.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ import UserAvatar from '@/components/common/UserAvatar.vue'
101101
import UserCredit from '@/components/common/UserCredit.vue'
102102
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
103103
import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions'
104+
import { useExternalLink } from '@/composables/useExternalLink'
104105
import SubscribeButton from '@/platform/cloud/subscription/components/SubscribeButton.vue'
105106
import { useSubscription } from '@/platform/cloud/subscription/composables/useSubscription'
106107
import { isCloud } from '@/platform/distribution/types'
@@ -111,6 +112,8 @@ const emit = defineEmits<{
111112
close: []
112113
}>()
113114
115+
const { buildDocsUrl } = useExternalLink()
116+
114117
const planSettingsLabel = isCloud
115118
? 'settingsCategories.PlanCredits'
116119
: 'settingsCategories.Credits'
@@ -145,7 +148,9 @@ const handleTopUp = () => {
145148
146149
const handleOpenPartnerNodesInfo = () => {
147150
window.open(
148-
'https://docs.comfy.org/tutorials/api-nodes/overview#api-nodes',
151+
buildDocsUrl('/tutorials/api-nodes/overview#api-nodes', {
152+
includeLocale: true
153+
}),
149154
'_blank'
150155
)
151156
emit('close')

src/components/topbar/LoginButton.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div>
2323
<div class="mb-1">{{ t('auth.loginButton.tooltipHelp') }}</div>
2424
<a
25-
href="https://docs.comfy.org/tutorials/api-nodes/overview#api-nodes"
25+
:href="apiNodesOverviewUrl"
2626
target="_blank"
2727
class="text-neutral-500 hover:text-primary"
2828
>{{ t('auth.loginButton.tooltipLearnMore') }}</a
@@ -37,9 +37,17 @@ import Popover from 'primevue/popover'
3737
import { ref } from 'vue'
3838
3939
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
40+
import { useExternalLink } from '@/composables/useExternalLink'
4041
import { t } from '@/i18n'
4142
4243
const { isLoggedIn, handleSignIn } = useCurrentUser()
44+
const { buildDocsUrl } = useExternalLink()
45+
const apiNodesOverviewUrl = buildDocsUrl(
46+
'/tutorials/api-nodes/overview#api-nodes',
47+
{
48+
includeLocale: true
49+
}
50+
)
4351
const popoverRef = ref<InstanceType<typeof Popover> | null>(null)
4452
let hideTimeout: ReturnType<typeof setTimeout> | null = null
4553
let showTimeout: ReturnType<typeof setTimeout> | null = null

src/composables/useCoreCommands.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useCurrentUser } from '@/composables/auth/useCurrentUser'
22
import { useFirebaseAuthActions } from '@/composables/auth/useFirebaseAuthActions'
33
import { useSelectedLiteGraphItems } from '@/composables/canvas/useSelectedLiteGraphItems'
4+
import { useExternalLink } from '@/composables/useExternalLink'
45
import { useModelSelectorDialog } from '@/composables/useModelSelectorDialog'
56
import {
67
DEFAULT_DARK_COLOR_PALETTE,
@@ -76,6 +77,7 @@ export function useCoreCommands(): ComfyCommand[] {
7677
const canvasStore = useCanvasStore()
7778
const executionStore = useExecutionStore()
7879
const telemetry = useTelemetry()
80+
const { staticUrls, buildDocsUrl } = useExternalLink()
7981

8082
const bottomPanelStore = useBottomPanelStore()
8183

@@ -761,10 +763,7 @@ export function useCoreCommands(): ComfyCommand[] {
761763
is_external: true,
762764
source: 'menu'
763765
})
764-
window.open(
765-
'https://github.com/comfyanonymous/ComfyUI/issues',
766-
'_blank'
767-
)
766+
window.open(staticUrls.githubIssues, '_blank')
768767
}
769768
},
770769
{
@@ -779,7 +778,7 @@ export function useCoreCommands(): ComfyCommand[] {
779778
is_external: true,
780779
source: 'menu'
781780
})
782-
window.open('https://docs.comfy.org/', '_blank')
781+
window.open(buildDocsUrl('/', { includeLocale: true }), '_blank')
783782
}
784783
},
785784
{
@@ -794,7 +793,7 @@ export function useCoreCommands(): ComfyCommand[] {
794793
is_external: true,
795794
source: 'menu'
796795
})
797-
window.open('https://www.comfy.org/discord', '_blank')
796+
window.open(staticUrls.discord, '_blank')
798797
}
799798
},
800799
{
@@ -861,7 +860,7 @@ export function useCoreCommands(): ComfyCommand[] {
861860
is_external: true,
862861
source: 'menu'
863862
})
864-
window.open('https://forum.comfy.org/', '_blank')
863+
window.open(staticUrls.forum, '_blank')
865864
}
866865
},
867866
{

src/composables/useExternalLink.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { computed } from 'vue'
2+
3+
import { electronAPI, isElectron } from '@/utils/envUtil'
4+
import { useI18n } from 'vue-i18n'
5+
6+
/**
7+
* Composable for building docs.comfy.org URLs with automatic locale and platform detection
8+
*
9+
* @example
10+
* ```ts
11+
* const { buildDocsUrl } = useExternalLink()
12+
*
13+
* // Simple usage
14+
* const changelogUrl = buildDocsUrl('/changelog', { includeLocale: true })
15+
* // => 'https://docs.comfy.org/zh-CN/changelog' (if Chinese)
16+
*
17+
* // With platform detection
18+
* const desktopUrl = buildDocsUrl('/installation/desktop', {
19+
* includeLocale: true,
20+
* platform: true
21+
* })
22+
* // => 'https://docs.comfy.org/zh-CN/installation/desktop/macos' (if Chinese + macOS)
23+
* ```
24+
*/
25+
export function useExternalLink() {
26+
const { locale } = useI18n()
27+
28+
const isChinese = computed(() => {
29+
return locale.value === 'zh' || locale.value === 'zh-TW'
30+
})
31+
32+
const platform = computed(() => {
33+
if (!isElectron()) {
34+
return null
35+
}
36+
37+
const electronPlatform = electronAPI().getPlatform()
38+
return electronPlatform === 'darwin' ? 'macos' : 'windows'
39+
})
40+
41+
/**
42+
* Build a docs.comfy.org URL with optional locale and platform
43+
*
44+
* @param path - The path after the domain (e.g., '/installation/desktop')
45+
* @param options - Options for building the URL
46+
* @param options.includeLocale - Whether to include locale prefix (default: false)
47+
* @param options.platform - Whether to include platform suffix (default: false)
48+
* @returns The complete docs URL
49+
*
50+
* @example
51+
* ```ts
52+
* buildDocsUrl('/changelog') // => 'https://docs.comfy.org/changelog'
53+
* buildDocsUrl('/changelog', { includeLocale: true }) // => 'https://docs.comfy.org/zh-CN/changelog' (if Chinese)
54+
* buildDocsUrl('/installation/desktop', { includeLocale: true, platform: true })
55+
* // => 'https://docs.comfy.org/zh-CN/installation/desktop/macos' (if Chinese + macOS)
56+
* ```
57+
*/
58+
const buildDocsUrl = (
59+
path: string,
60+
options: {
61+
includeLocale?: boolean
62+
platform?: boolean
63+
} = {}
64+
): string => {
65+
const { includeLocale = false, platform: includePlatform = false } = options
66+
67+
let url = 'https://docs.comfy.org'
68+
69+
if (includeLocale && isChinese.value) {
70+
url += '/zh-CN'
71+
}
72+
73+
const normalizedPath = path.startsWith('/') ? path : `/${path}`
74+
url += normalizedPath
75+
76+
if (includePlatform && platform.value) {
77+
url = url.endsWith('/') ? url : `${url}/`
78+
url += platform.value
79+
}
80+
81+
return url
82+
}
83+
84+
const staticUrls = {
85+
// Static external URLs
86+
discord: 'https://www.comfy.org/discord',
87+
github: 'https://github.com/comfyanonymous/ComfyUI',
88+
githubIssues: 'https://github.com/comfyanonymous/ComfyUI/issues',
89+
githubFrontend: 'https://github.com/Comfy-Org/ComfyUI_frontend',
90+
githubElectron: 'https://github.com/Comfy-Org/electron',
91+
forum: 'https://forum.comfy.org/',
92+
comfyOrg: 'https://www.comfy.org/'
93+
}
94+
95+
return {
96+
buildDocsUrl,
97+
staticUrls
98+
}
99+
}

0 commit comments

Comments
 (0)