feat(v2): generalize usage of _ prefix convention to exclude content files/folders (#5173)

* create a swizzleWarning partial for shared text

* Generalize usage of _ prefix convention to exclude content files/folders

* add api doc

* MDX loader should not expect metadata/frontmatter on MDX partial files
This commit is contained in:
Sébastien Lorber 2021-07-15 13:21:41 +02:00 committed by GitHub
parent 0851e0e5bf
commit 8bdb3da233
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 249 additions and 80 deletions

View file

@ -0,0 +1,35 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Globby/Micromatch are the 2 libs we use in Docusaurus consistently
export {default as Globby} from 'globby';
import Micromatch from 'micromatch'; // Note: Micromatch is used by Globby
// The default patterns we ignore when globbing
// using _ prefix for exclusion by convention
export const GlobExcludeDefault = [
// Ignore files starting with _
'**/_*.{js,jsx,ts,tsx,md,mdx}',
// Ignore folders starting with _ (including folder content)
'**/_*/**',
// Ignore tests
'**/*.test.{js,jsx,ts,tsx}',
'**/__tests__/**',
];
type Matcher = (str: string) => boolean;
export function createMatcher(patterns: string[]): Matcher {
const regexp = new RegExp(
patterns.map((pattern) => Micromatch.makeRe(pattern).source).join('|'),
);
return (str) => regexp.test(str);
}

View file

@ -31,6 +31,7 @@ export * from './markdownParser';
export * from './markdownLinks';
export * from './escapePath';
export {md5Hash, simpleHash, docuHash} from './hashUtils';
export {Globby, GlobExcludeDefault, createMatcher} from './globUtils';
const fileHash = new Map();
export async function generate(