mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +02:00
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:
parent
0851e0e5bf
commit
8bdb3da233
40 changed files with 249 additions and 80 deletions
35
packages/docusaurus-utils/src/globUtils.ts
Normal file
35
packages/docusaurus-utils/src/globUtils.ts
Normal 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);
|
||||
}
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue