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

pull/3115/head
Divyansh Singh 1 year 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 { 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 { site } = useData()
const { pathname, search, hash } = new URL(url, 'http://a.com')
const normalizedPath = const normalizedPath =
pathname.endsWith('/') || pathname.endsWith('.html') pathname.endsWith('/') || pathname.endsWith('.html')

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

Loading…
Cancel
Save