diff --git a/src/client/theme-default/support/utils.ts b/src/client/theme-default/support/utils.ts index 3d05e9f5..1cd168cd 100644 --- a/src/client/theme-default/support/utils.ts +++ b/src/client/theme-default/support/utils.ts @@ -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') diff --git a/src/node/markdown/plugins/link.ts b/src/node/markdown/plugins/link.ts index 9aa29c96..841cd4cd 100644 --- a/src/node/markdown/plugins/link.ts +++ b/src/node/markdown/plugins/link.ts @@ -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) ) {