Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --ignore-paths option #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')}`);
Expand All @@ -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,
};

Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const presetConfig = {
pattern: '**/*.md',
ignore: [ '**/node_modules' ],
ignoreFootnotes: false,
ignorePaths: [],
cwd: process.cwd(),
exitLevel: 'error',
slugify: defaultSlugify,
Expand Down Expand Up @@ -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}`)
Expand Down Expand Up @@ -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))
Expand Down