|
|
@ -1,23 +1,23 @@
|
|
|
|
import { computed } from 'vue'
|
|
|
|
import { computed, Ref } from 'vue'
|
|
|
|
import { useRoute } from 'vitepress'
|
|
|
|
import { useRoute } from 'vitepress'
|
|
|
|
import type { DefaultTheme } from '../config'
|
|
|
|
import type { DefaultTheme } from '../config'
|
|
|
|
import { isExternal as isExternalCheck } from '../utils'
|
|
|
|
import { isExternal as isExternalCheck } from '../utils'
|
|
|
|
import { useUrl } from '../composables/url'
|
|
|
|
import { useUrl } from '../composables/url'
|
|
|
|
|
|
|
|
|
|
|
|
export function useNavLink(item: DefaultTheme.NavItemWithLink) {
|
|
|
|
export function useNavLink(item: Ref<DefaultTheme.NavItemWithLink>) {
|
|
|
|
const route = useRoute()
|
|
|
|
const route = useRoute()
|
|
|
|
const { withBase } = useUrl()
|
|
|
|
const { withBase } = useUrl()
|
|
|
|
|
|
|
|
|
|
|
|
const isExternal = isExternalCheck(item.link)
|
|
|
|
const isExternal = isExternalCheck(item.value.link)
|
|
|
|
|
|
|
|
|
|
|
|
const props = computed(() => {
|
|
|
|
const props = computed(() => {
|
|
|
|
const routePath = normalizePath(route.path)
|
|
|
|
const routePath = normalizePath(route.path)
|
|
|
|
|
|
|
|
|
|
|
|
let active = false
|
|
|
|
let active = false
|
|
|
|
if (item.activeMatch) {
|
|
|
|
if (item.value.activeMatch) {
|
|
|
|
active = new RegExp(item.activeMatch).test(routePath)
|
|
|
|
active = new RegExp(item.value.activeMatch).test(routePath)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
const itemPath = normalizePath(withBase(item.link))
|
|
|
|
const itemPath = normalizePath(withBase(item.value.link))
|
|
|
|
active =
|
|
|
|
active =
|
|
|
|
itemPath === '/'
|
|
|
|
itemPath === '/'
|
|
|
|
? itemPath === routePath
|
|
|
|
? itemPath === routePath
|
|
|
@ -29,10 +29,10 @@ export function useNavLink(item: DefaultTheme.NavItemWithLink) {
|
|
|
|
active,
|
|
|
|
active,
|
|
|
|
isExternal
|
|
|
|
isExternal
|
|
|
|
},
|
|
|
|
},
|
|
|
|
href: isExternal ? item.link : withBase(item.link),
|
|
|
|
href: isExternal ? item.value.link : withBase(item.value.link),
|
|
|
|
target: item.target || isExternal ? `_blank` : null,
|
|
|
|
target: item.value.target || isExternal ? `_blank` : null,
|
|
|
|
rel: item.rel || isExternal ? `noopener noreferrer` : null,
|
|
|
|
rel: item.value.rel || isExternal ? `noopener noreferrer` : null,
|
|
|
|
'aria-label': item.ariaLabel
|
|
|
|
'aria-label': item.value.ariaLabel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|