Skip to content

Commit

Permalink
fix: don't normalize non-html/non-http links (#3114)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Oct 21, 2023
1 parent a13f5cb commit da3d781
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/client/theme-default/support/utils.ts
Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/node/markdown/plugins/link.ts
Expand Up @@ -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)
) {
Expand Down

0 comments on commit da3d781

Please sign in to comment.