fix(build): prepend base to all internal non-relative links (#1908)

BREAKING CHANGE: `base` is now appended to all internal (non-relative) links, including any reference to a file present in the public directory. If you want the earlier behavior for such links, use absolute links.
pull/1930/head
Juan Martín Seery 2 years ago committed by GitHub
parent dd0c4c698c
commit dcf29419f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,15 +36,22 @@ export const linkPlugin = (
pushLink(url, env)
}
hrefAttr[1] = url.replace(PATHNAME_PROTOCOL_RE, '')
} else if (
// internal anchor links
!url.startsWith('#') &&
// mail links
!url.startsWith('mailto:') &&
// links to files (other than html/md)
!/\.(?!html|md)\w+($|\?)/i.test(url)
) {
normalizeHref(hrefAttr, env)
} else {
if (
// internal anchor links
!url.startsWith('#') &&
// mail links
!url.startsWith('mailto:') &&
// links to files (other than html/md)
!/\.(?!html|md)\w+($|\?)/i.test(url)
) {
normalizeHref(hrefAttr, env)
}
// append base to internal (non-relative) urls
if (hrefAttr[1].startsWith('/')) {
hrefAttr[1] = `${base}${hrefAttr[1]}`.replace(/\/+/g, '/')
}
}
// encode vite-specific replace strings in case they appear in URLs
@ -90,11 +97,6 @@ export const linkPlugin = (
// export it for existence check
pushLink(url.replace(/\.html$/, ''), env)
// append base to internal (non-relative) urls
if (url.startsWith('/')) {
url = `${base}${url}`.replace(/\/+/g, '/')
}
// markdown-it encodes the uri
hrefAttr[1] = decodeURI(url)
}

Loading…
Cancel
Save