Skip to content

Commit

Permalink
fix: don't add .html to urls of non-html files (#515)
Browse files Browse the repository at this point in the history
fix #265
  • Loading branch information
brc-dd committed Feb 22, 2022
1 parent 804954c commit 34d1542
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/node/markdown/plugins/link.ts
Expand Up @@ -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)
}
Expand All @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions src/node/markdownToVue.ts
Expand Up @@ -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
Expand Down

0 comments on commit 34d1542

Please sign in to comment.