export function resolveFusionMarkdownURL()

in site/src/buildtime/fetchFusionDocFromGithub/fetchFusionDoc.ts [21:60]


export function resolveFusionMarkdownURL({
  componentName,
  linkURL,
}: {
  componentName?: string
  linkURL?: string
}) {
  let actualComponentName: string | undefined
  if (componentName) {
    actualComponentName = componentName
  }
  if (!actualComponentName) {
    const matchGithubRawContent =
      linkURL &&
      linkURL.match(
        /^https:\/\/raw.githubusercontent.com\/alibaba-fusion\/next\/master\/docs\/([^/]+)\/index.md$/
      )
    if (matchGithubRawContent) {
      actualComponentName = matchGithubRawContent[1]
    }
  }
  if (!actualComponentName) {
    const matchGithub =
      linkURL &&
      linkURL.match(
        /https:\/\/github.com\/alibaba-fusion\/next\/blob\/master\/docs\/([^/]+)\/index.md$/
      )
    if (matchGithub) {
      actualComponentName = matchGithub[1]
    }
  }

  if (!actualComponentName)
    throw new Error(`无法从markdown中的link指令解析出fusion组件名称`)

  return {
    actualComponentName,
    url: `https://raw.githubusercontent.com/alibaba-fusion/next/master/docs/${actualComponentName}/index.md`,
  }
}