fix(theme): incorrect link external parsing (#396)

This commit is contained in:
pengzhanbo 2024-12-23 23:10:24 +08:00 committed by GitHub
parent f21c42a3c7
commit 4e158964d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,8 +3,6 @@ import { computed, type MaybeRefOrGetter, toValue } from 'vue'
import { resolveRouteFullPath, useRoute } from 'vuepress/client'
import { useData } from './data.js'
const ENDING_SLASH = /(?:\/|\.(?:md|html))$/i
export function useLink(
href: MaybeRefOrGetter<string | undefined>,
target?: MaybeRefOrGetter<string | undefined>,
@ -19,8 +17,10 @@ export function useLink(
return false
if (rawTarget === '_blank' || isLinkExternal(link))
return true
const pathname = link.split(/[#?]/)[0]
return !ENDING_SLASH.test(pathname)
const filename = link.split(/[#?]/)[0]?.split('/').pop() || ''
if (filename === '' || filename.endsWith('.html') || filename.endsWith('.md'))
return false
return filename.includes('.')
})
const link = computed(() => {