diff --git a/bin.js b/bin.js index 7913401..f56e8d5 100755 --- a/bin.js +++ b/bin.js @@ -14,6 +14,7 @@ const program = new Command() .option('-p, --preset [name]', `Preset config(eg ${Object.keys(presetConfig).join(', ')})`) .option('-P, --pattern [pattern]', `Glob patterns, default to ${presetConfig.default.pattern}`) .option('-i, --ignore [pattern]', `Ignore patterns, will merge to pattern, default to ${presetConfig.default.ignore.join(',')}`) + .option('--ignore-path [path]', 'Ignore path(s) from lookup') .option('--ignore-footnotes', `Ignore footnotes, default to ${presetConfig.default.ignoreFootnotes}`) .option('--exit-level [level]', `Process exit level, default to ${presetConfig.default.exitLevel}, other choice is warn and none, it will not exit if setting to none`) .option('--default-index [index]', `Default index in directory, default to ${presetConfig.default.defaultIndex.join(',')}`); @@ -28,6 +29,7 @@ const options = { pattern: program.pattern ? program.pattern.split(',') : undefined, ignore: program.ignore ? program.ignore.split(',') : undefined, ignoreFootnotes: program.ignoreFootnotes, + ignorePaths: program.ignorePath ? program.ignorePath.split(',') : undefined, defaultIndex: program.defaultIndex ? program.defaultIndex.split(',') : undefined, }; diff --git a/index.js b/index.js index 9d7a384..cd2f4c4 100644 --- a/index.js +++ b/index.js @@ -35,6 +35,7 @@ const presetConfig = { pattern: '**/*.md', ignore: [ '**/node_modules' ], ignoreFootnotes: false, + ignorePaths: [], cwd: process.cwd(), exitLevel: 'error', slugify: defaultSlugify, @@ -219,7 +220,7 @@ function initOption(options) { */ async function check(options) { options = initOption(options); - const { cwd, defaultIndex, root, fix, pattern, ignore, ignoreFootnotes } = options; + const { cwd, defaultIndex, root, fix, pattern, ignore, ignoreFootnotes, ignorePaths } = options; assert(Array.isArray(root), 'options.root must be array'); const globPattern = (Array.isArray(pattern) ? pattern : [ pattern ]).concat( (Array.isArray(ignore) ? ignore : [ ignore ]).map(p => `!${p}`) @@ -300,7 +301,7 @@ async function check(options) { let ext = path.extname(pathname); let matchAbUrl; - if (pathname) { + if (pathname && !ignorePaths.includes(pathname)) { if (pathname.charAt(0) === '/') { // find exist file matchAbUrl = root.map(r => normalizeUrl(path.join(cwd, r, pathname.substring(1)), ext))