diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index 335b1a019f9d..164200240aa6 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -16,7 +16,7 @@ import { reportMessage, posixPath, addTrailingPathSeparator, - createExcludeMatcher, + createMatcher, } from '@docusaurus/utils'; import { STATIC_DIR_NAME, @@ -460,7 +460,7 @@ export default function pluginContentBlog( beforeDefaultRemarkPlugins, beforeDefaultRehypePlugins, staticDir: path.join(siteDir, STATIC_DIR_NAME), - isMDXPartial: createExcludeMatcher(options.exclude), + isMDXPartial: createMatcher(options.exclude), metadataPath: (mdxPath: string) => { // Note that metadataPath must be the same/in-sync as // the path from createData for each MDX. diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index d8670c1440ae..a79438ad5126 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -18,7 +18,7 @@ import { reportMessage, posixPath, addTrailingPathSeparator, - createExcludeMatcher, + createMatcher, } from '@docusaurus/utils'; import {LoadContext, Plugin, RouteConfig} from '@docusaurus/types'; import {loadSidebars, createSidebarsUtils, processSidebars} from './sidebars'; @@ -409,7 +409,7 @@ export default function pluginContentDocs( beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, staticDir: path.join(siteDir, STATIC_DIR_NAME), - isMDXPartial: createExcludeMatcher(options.exclude), + isMDXPartial: createMatcher(options.exclude), metadataPath: (mdxPath: string) => { // Note that metadataPath must be the same/in-sync as // the path from createData for each MDX. diff --git a/packages/docusaurus-plugin-content-pages/src/index.ts b/packages/docusaurus-plugin-content-pages/src/index.ts index 12d9785474c7..01b40bcd8474 100644 --- a/packages/docusaurus-plugin-content-pages/src/index.ts +++ b/packages/docusaurus-plugin-content-pages/src/index.ts @@ -16,7 +16,7 @@ import { getFolderContainingFile, addTrailingPathSeparator, Globby, - createExcludeMatcher, + createMatcher, } from '@docusaurus/utils'; import { LoadContext, @@ -217,7 +217,7 @@ export default function pluginContentPages( beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, staticDir: path.join(siteDir, STATIC_DIR_NAME), - isMDXPartial: createExcludeMatcher(options.exclude), + isMDXPartial: createMatcher(options.exclude), metadataPath: (mdxPath: string) => { // Note that metadataPath must be the same/in-sync as // the path from createData for each MDX. diff --git a/packages/docusaurus-utils/src/globUtils.ts b/packages/docusaurus-utils/src/globUtils.ts index dbd2e082020f..96c000bcc6b7 100644 --- a/packages/docusaurus-utils/src/globUtils.ts +++ b/packages/docusaurus-utils/src/globUtils.ts @@ -25,12 +25,11 @@ export const GlobExcludeDefault = [ '**/__tests__/**', ]; -type ExcludeMatcher = (path: string) => boolean; -export function createExcludeMatcher(exclude: string[]): ExcludeMatcher { +type Matcher = (str: string) => boolean; + +export function createMatcher(patterns: string[]): Matcher { const regexp = new RegExp( - exclude.map((pattern) => Micromatch.makeRe(pattern).source).join('|'), + patterns.map((pattern) => Micromatch.makeRe(pattern).source).join('|'), ); - return function isExcluded(str: string) { - return regexp.test(str); - }; + return (str) => regexp.test(str); } diff --git a/packages/docusaurus-utils/src/index.ts b/packages/docusaurus-utils/src/index.ts index 0fef74454a1f..2db5ff378de1 100644 --- a/packages/docusaurus-utils/src/index.ts +++ b/packages/docusaurus-utils/src/index.ts @@ -31,7 +31,7 @@ export * from './markdownParser'; export * from './markdownLinks'; export * from './escapePath'; export {md5Hash, simpleHash, docuHash} from './hashUtils'; -export {Globby, GlobExcludeDefault, createExcludeMatcher} from './globUtils'; +export {Globby, GlobExcludeDefault, createMatcher} from './globUtils'; const fileHash = new Map(); export async function generate(