Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/node/markdown/plugins/link.ts
Expand Up @@ -32,7 +32,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)
}
Expand All @@ -55,7 +57,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')
Expand Down
2 changes: 2 additions & 0 deletions src/node/markdownToVue.ts
Expand Up @@ -104,6 +104,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
Expand Down