From 66ce654d5be9c26ba69cc75ac12ff6662410c69d Mon Sep 17 00:00:00 2001 From: ale Date: Sun, 2 Sep 2018 11:16:49 +0100 Subject: Add --exclude and --exclude-file options Allow users to add to the exclude regexp lists easily. --- scope.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'scope.go') diff --git a/scope.go b/scope.go index b2e90ea..bda1035 100644 --- a/scope.go +++ b/scope.go @@ -115,19 +115,21 @@ func (s *regexpIgnoreScope) Check(link Outlink, depth int) bool { return true } +func compileDefaultIgnorePatterns() []*regexp.Regexp { + out := make([]*regexp.Regexp, 0, len(defaultIgnorePatterns)) + for _, p := range defaultIgnorePatterns { + out = append(out, regexp.MustCompile(p)) + } + return out +} + // NewRegexpIgnoreScope returns a Scope that filters out URLs // according to a list of regular expressions. -func NewRegexpIgnoreScope(ignores []string) Scope { - if ignores == nil { - ignores = defaultIgnorePatterns - } - r := regexpIgnoreScope{ - ignores: make([]*regexp.Regexp, 0, len(ignores)), - } - for _, i := range ignores { - r.ignores = append(r.ignores, regexp.MustCompile(i)) +func NewRegexpIgnoreScope(ignores []*regexp.Regexp) Scope { + ignores = append(compileDefaultIgnorePatterns(), ignores...) + return ®expIgnoreScope{ + ignores: ignores, } - return &r } // NewIncludeRelatedScope always includes resources with TagRelated. -- cgit v1.2.3-54-g00ecf