Skip to content

Commit

Permalink
Merge pull request #278 from CanadaHonk/ignore-option
Browse files Browse the repository at this point in the history
feat: add basic ignore subpaths argument
  • Loading branch information
tcort committed Mar 10, 2024
2 parents ee023b8 + 4bf03da commit cedaaeb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion markdown-link-check
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Input {
}
}

function commaSeparatedPathsList(value) {
return value.split(',');
}

function commaSeparatedCodesList(value, dummyPrevious) {
return value.split(',').map(function(item) {
return parseInt(item, 10);
Expand All @@ -35,6 +39,7 @@ function getInputs() {
.option('-c, --config [config]', 'apply a config file (JSON), holding e.g. url specific header configuration')
.option('-q, --quiet', 'displays errors only')
.option('-v, --verbose', 'displays detailed error information')
.option('-i --ignore <paths>', 'ignore input paths including an ignore path', commaSeparatedPathsList)
.option('-a, --alive <code>', 'comma separated list of HTTP codes to be considered as alive', commaSeparatedCodesList)
.option('-r, --retry', 'retry after the duration indicated in \'retry-after\' header when HTTP code is 429')
.option('--projectBaseUrl <url>', 'the URL to use for {{BASEURL}} replacement')
Expand Down Expand Up @@ -84,7 +89,16 @@ function getInputs() {
console.error(chalk.red('\nERROR: ' + filenameOrUrl + ' is a directory! Please provide a valid filename as an argument.'));
process.exit(1);
}
baseUrl = 'file://' + path.dirname(path.resolve(filenameOrUrl));

const resolved = path.resolve(filenameOrUrl);

// skip paths given if it includes a path to ignore.
// todo: allow ignore paths to be glob or regex instead of just includes?
if (program.opts().ignore.some((ignorePath) => resolved.includes(ignorePath))) {
continue;
}

baseUrl = 'file://' + path.dirname(resolved);
stream = fs.createReadStream(filenameOrUrl);
}

Expand Down

0 comments on commit cedaaeb

Please sign in to comment.