mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-06 10:38:31 +08:00
33 lines
805 B
TypeScript
33 lines
805 B
TypeScript
import { computed } from 'vue'
|
|
import { useData } from 'vitepress'
|
|
import { createGitHubUrl } from '../utils'
|
|
|
|
export function useEditLink() {
|
|
const { page, theme, frontmatter } = useData()
|
|
const url = computed(() => {
|
|
const {
|
|
repo,
|
|
docsDir = '',
|
|
docsBranch = 'dev',
|
|
docsRepo = repo,
|
|
editLinks,
|
|
} = theme.value
|
|
const showEditLink =
|
|
frontmatter.value.editLink != null
|
|
? frontmatter.value.editLink
|
|
: editLinks
|
|
const { relativePath } = page.value
|
|
if (!showEditLink || !relativePath || !repo) {
|
|
return null
|
|
}
|
|
return createGitHubUrl(docsRepo, docsDir, docsBranch, relativePath, '', '')
|
|
})
|
|
const text = computed(() => {
|
|
return theme.value.editLinkText || 'Edit this page'
|
|
})
|
|
return {
|
|
url,
|
|
text,
|
|
}
|
|
}
|