fix: don't normalize non-html/non-http links (#3114)

pull/3115/head
Divyansh Singh 12 months ago committed by GitHub
parent a13f5cb3a7
commit da3d7812a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,10 +21,17 @@ export function ensureStartingSlash(path: string): string {
}
export function normalizeLink(url: string): string {
if (isExternal(url)) return url
const { pathname, search, hash, protocol } = new URL(url, 'http://a.com')
if (
isExternal(url) ||
url.startsWith('#') ||
!protocol.startsWith('http') ||
/\.(?!html|md)\w+($|\?)/i.test(url)
)
return url
const { site } = useData()
const { pathname, search, hash } = new URL(url, 'http://a.com')
const normalizedPath =
pathname.endsWith('/') || pathname.endsWith('.html')

@ -38,8 +38,8 @@ export const linkPlugin = (
if (
// internal anchor links
!url.startsWith('#') &&
// mail links
!url.startsWith('mailto:') &&
// mail/custom protocol links
new URL(url, 'http://a.com').protocol.startsWith('http') &&
// links to files (other than html/md)
!/\.(?!html|md)\w+($|\?)/i.test(url)
) {

Loading…
Cancel
Save