Skip to content

Commit 52d6672

Browse files
committed
fix: handle index.md when checking relative links
1 parent 14d4d25 commit 52d6672

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/webpack/markdownLoader.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,19 @@ module.exports = function (src) {
5858

5959
// check if relative links are valid
6060
links && links.forEach(link => {
61-
const filename = link
61+
const shortname = link
6262
.replace(/#[\w-]*$/, '')
6363
.replace(/\.html$/, '.md')
64+
const filename = shortname
6465
.replace(/\/$/, '/README.md')
6566
.replace(/^\//, sourceDir + '/')
66-
const file = path.resolve(path.dirname(this.resourcePath), filename)
67-
if (!fs.existsSync(file)) {
67+
const altname = shortname
68+
.replace(/\/$/, '/index.md')
69+
.replace(/^\//, sourceDir + '/')
70+
const dir = path.dirname(this.resourcePath)
71+
const file = path.resolve(dir, filename)
72+
const altfile = altname !== filename ? path.resolve(dir, altname) : null
73+
if (!fs.existsSync(file) && (altfile && !fs.existsSync(altfile))) {
6874
this.emitWarning(
6975
new Error(
7076
`\nFile for relative link "${link}" does not exist.\n` +

0 commit comments

Comments
 (0)