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

@ -25,9 +25,7 @@
"@docusaurus/utils-validation": "2.0.0-beta.3",
"globby": "^11.0.2",
"lodash": "^4.17.20",
"minimatch": "^3.0.4",
"remark-admonitions": "^1.2.1",
"slash": "^3.0.0",
"tslib": "^2.1.0",
"webpack": "^5.40.0"
},

View file

@ -5,11 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/
import globby from 'globby';
import fs from 'fs';
import path from 'path';
import minimatch from 'minimatch';
import slash from 'slash';
import {
encodePath,
fileToPath,
@ -18,6 +15,8 @@ import {
getPluginI18nPath,
getFolderContainingFile,
addTrailingPathSeparator,
Globby,
createMatcher,
} from '@docusaurus/utils';
import {
LoadContext,
@ -81,11 +80,6 @@ export default function pluginContentPages(
);
const dataDir = path.join(pluginDataDirRoot, options.id ?? DEFAULT_PLUGIN_ID);
const excludeRegex = new RegExp(
options.exclude
.map((pattern) => minimatch.makeRe(pattern).source)
.join('|'),
);
return {
name: 'docusaurus-plugin-content-pages',
@ -116,7 +110,7 @@ export default function pluginContentPages(
}
const {baseUrl} = siteConfig;
const pagesFiles = await globby(include, {
const pagesFiles = await Globby(include, {
cwd: contentPaths.contentPath,
ignore: options.exclude,
});
@ -223,20 +217,16 @@ export default function pluginContentPages(
beforeDefaultRehypePlugins,
beforeDefaultRemarkPlugins,
staticDir: path.join(siteDir, STATIC_DIR_NAME),
// Note that metadataPath must be the same/in-sync as
// the path from createData for each MDX.
isMDXPartial: createMatcher(options.exclude),
metadataPath: (mdxPath: string) => {
if (excludeRegex.test(slash(mdxPath))) {
return null;
}
// Note that metadataPath must be the same/in-sync as
// the path from createData for each MDX.
const aliasedSource = aliasedSitePath(mdxPath, siteDir);
return path.join(
dataDir,
`${docuHash(aliasedSource)}.json`,
);
},
forbidFrontMatter: (mdxPath: string) =>
excludeRegex.test(slash(mdxPath)),
},
},
{

View file

@ -11,22 +11,19 @@ import {
RehypePluginsSchema,
AdmonitionsSchema,
} from '@docusaurus/utils-validation';
import {GlobExcludeDefault} from '@docusaurus/utils';
export const DEFAULT_OPTIONS: PluginOptions = {
path: 'src/pages', // Path to data on filesystem, relative to site dir.
routeBasePath: '/', // URL Route.
include: ['**/*.{js,jsx,ts,tsx,md,mdx}'], // Extensions to include.
exclude: GlobExcludeDefault,
mdxPageComponent: '@theme/MDXPage',
remarkPlugins: [],
rehypePlugins: [],
beforeDefaultRehypePlugins: [],
beforeDefaultRemarkPlugins: [],
admonitions: {},
exclude: [
'**/_*.{js,jsx,ts,tsx,md,mdx}',
'**/*.test.{js,ts}',
'**/__tests__/**',
],
};
export const PluginOptionSchema = Joi.object({