Skip to content

Commit

Permalink
rename util api to createMatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Jul 15, 2021
1 parent 454788f commit f9222e2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
reportMessage,
posixPath,
addTrailingPathSeparator,
createExcludeMatcher,
createMatcher,
} from '@docusaurus/utils';
import {
STATIC_DIR_NAME,
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-pages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
getFolderContainingFile,
addTrailingPathSeparator,
Globby,
createExcludeMatcher,
createMatcher,
} from '@docusaurus/utils';
import {
LoadContext,
Expand Down Expand Up @@ -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.
Expand Down
11 changes: 5 additions & 6 deletions packages/docusaurus-utils/src/globUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion packages/docusaurus-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f9222e2

Please sign in to comment.