mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-24 11:08:16 +08:00
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import type { ComputedRef } from 'vue'
|
|
import type { NavItemWithLink } from '../../shared/index.js'
|
|
import { computed } from 'vue'
|
|
import { resolveEditLink } from '../utils/index.js'
|
|
import { useData } from './data.js'
|
|
import { useThemeData } from './theme-data.js'
|
|
|
|
export function useEditLink(): ComputedRef<null | NavItemWithLink> {
|
|
const { theme, page, frontmatter } = useData()
|
|
const themeData = useThemeData()
|
|
|
|
return computed(() => {
|
|
const showEditLink
|
|
= frontmatter.value.editLink ?? themeData.value.editLink ?? true
|
|
if (!showEditLink)
|
|
return null
|
|
|
|
const {
|
|
docsRepo,
|
|
docsBranch = 'main',
|
|
docsDir = '',
|
|
} = themeData.value
|
|
const { editLinkText } = theme.value
|
|
|
|
if (!docsRepo)
|
|
return null
|
|
|
|
const editLink = resolveEditLink({
|
|
docsRepo,
|
|
docsBranch,
|
|
docsDir,
|
|
filePathRelative: page.value.filePathRelative,
|
|
editLinkPattern:
|
|
frontmatter.value.editLinkPattern ?? theme.value.editLinkPattern,
|
|
})
|
|
|
|
if (!editLink)
|
|
return null
|
|
|
|
return {
|
|
text: editLinkText ?? 'Edit this page',
|
|
link: editLink,
|
|
}
|
|
})
|
|
}
|