mdx-link-checker
Advanced tools
Comparing version
34
index.js
@@ -17,9 +17,24 @@ "use strict"; | ||
let fileExt = filename.split('.').pop() | ||
if(["mdx", "md", "html", "htm"].indexOf(fileExt) == -1){ | ||
return | ||
} | ||
let markdown = fs.readFileSync(filePathAbs).toString(); | ||
let html = mdx.sync(markdown, { | ||
remarkPlugins: [ | ||
slugPlugin | ||
] | ||
}) | ||
let html = "" | ||
try { | ||
html = mdx.sync(markdown, { | ||
remarkPlugins: [ | ||
slugPlugin | ||
] | ||
}) | ||
} catch(e) { | ||
// Fail if there was an error parsing a mdx/md file | ||
if (fileExt === "mdx" || fileExt == "md") { | ||
console.error("Unable to parse mdx to html: " + filename) | ||
throw e | ||
} | ||
} | ||
if (!cache[filePathAbs]) { | ||
@@ -94,5 +109,8 @@ cache[filePathAbs] = { | ||
if (!cache[targetFile]) { | ||
exitCode = 1; | ||
console.error(`Link is broken: '${link.original}' in file ${data.filePathAbs}`) | ||
return; | ||
// make sure linked file does not exist | ||
if (fs.existsSync(path.join(path.dirname(file), link.original)) === false) { | ||
exitCode = 1; | ||
console.error(`Link is broken: '${link.original}' in file ${data.filePathAbs}`) | ||
return; | ||
} | ||
} | ||
@@ -99,0 +117,0 @@ } |
{ | ||
"name": "mdx-link-checker", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
3644
15.87%104
16.85%