feat(sitemap): add ignorePatterns option (#6979)

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
ApsarasX 2022-04-06 21:44:07 +08:00 committed by GitHub
parent bd70cfc1d7
commit 103ea04661
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 78 additions and 14 deletions

View file

@ -31,11 +31,16 @@ type Matcher = (str: string) => boolean;
* A very thin wrapper around `Micromatch.makeRe`.
*
* @see {@link createAbsoluteFilePathMatcher}
* @param patterns A list of glob patterns.
* @param patterns A list of glob patterns. If the list is empty, it defaults to
* matching none.
* @returns A matcher handle that tells if a file path is matched by any of the
* patterns.
*/
export function createMatcher(patterns: string[]): Matcher {
if (patterns.length === 0) {
// `/(?:)/.test("foo")` is `true`
return () => false;
}
const regexp = new RegExp(
patterns.map((pattern) => Micromatch.makeRe(pattern).source).join('|'),
);