fix: don't add .html to urls of non-html files (#515)

fix #265
pull/545/head
Divyansh Singh 2 years ago committed by GitHub
parent 804954cf4d
commit 34d1542f46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,7 +33,9 @@ export const linkPlugin = (
// internal anchor links
!url.startsWith('#') &&
// mail links
!url.startsWith('mailto:')
!url.startsWith('mailto:') &&
// links to files (other than html/md)
!/\.(?!html|md)\w+($|\?)/i.test(url)
) {
normalizeHref(hrefAttr)
}
@ -56,7 +58,7 @@ export const linkPlugin = (
const [, path, hash] = indexMatch
url = path + hash
} else {
let cleanUrl = url.replace(/\#.*$/, '').replace(/\?.*$/, '')
let cleanUrl = url.replace(/[?#].*$/, '')
// .md -> .html
if (cleanUrl.endsWith('.md')) {
cleanUrl = cleanUrl.replace(/\.md$/, '.html')

@ -107,6 +107,8 @@ export function createMarkdownToVueRenderFn(
if (data.links) {
const dir = path.dirname(file)
for (let url of data.links) {
if (/\.(?!html|md)\w+($|\?)/i.test(url)) continue
if (url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')) {
recordDeadLink(url)
continue

Loading…
Cancel
Save