Skip to content

Commit

Permalink
fix: handle index.md when checking relative links
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 18, 2018
1 parent 14d4d25 commit 52d6672
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/webpack/markdownLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,19 @@ module.exports = function (src) {

// check if relative links are valid
links && links.forEach(link => {
const filename = link
const shortname = link
.replace(/#[\w-]*$/, '')
.replace(/\.html$/, '.md')
const filename = shortname
.replace(/\/$/, '/README.md')
.replace(/^\//, sourceDir + '/')
const file = path.resolve(path.dirname(this.resourcePath), filename)
if (!fs.existsSync(file)) {
const altname = shortname
.replace(/\/$/, '/index.md')
.replace(/^\//, sourceDir + '/')
const dir = path.dirname(this.resourcePath)
const file = path.resolve(dir, filename)
const altfile = altname !== filename ? path.resolve(dir, altname) : null
if (!fs.existsSync(file) && (altfile && !fs.existsSync(altfile))) {
this.emitWarning(
new Error(
`\nFile for relative link "${link}" does not exist.\n` +
Expand Down

0 comments on commit 52d6672

Please sign in to comment.