index.ts 500 B

123456789101112131415161718
  1. import { isExternal } from 'vitepress/dist/client/shared.js'
  2. const endingSlashRE = /\/$/
  3. export function createGitHubUrl(
  4. docsRepo: string,
  5. docsDir: string,
  6. docsBranch: string,
  7. path: string,
  8. folder = 'examples/',
  9. ext = '.vue'
  10. ) {
  11. const base = isExternal(docsRepo)
  12. ? docsRepo
  13. : `https://github.com/${docsRepo}`
  14. return `${base.replace(endingSlashRE, '')}/edit/${docsBranch}/${
  15. docsDir ? `${docsDir.replace(endingSlashRE, '')}/` : ''
  16. }${folder || ''}${path}${ext || ''}`
  17. }