LCOV - code coverage report
Current view: top level - src/composables - useExternalLink.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 83.3 % 18 15
Test Date: 2026-11-17 04:17:53

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

Generated by: LCOV version 2.0-1