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

@ -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)),
},
},
{