mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-09 06:12:28 +02:00
feat(v2): add support to ignore files in pages plugin (#3196)
* add support to ignore pages
* fix import problem
* Update website/docs/guides/creating-pages.md
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
* Revert "fix import problem"
This reverts commit 4457a2e938
.
* revert
* fix slash
* forbid frontmatter
* fix formatting
* Update website/docs/guides/creating-pages.md
* Update website/src/pages/examples/_chapter1.md
* Update website/src/pages/examples/_chapter2.mdx
* Update website/src/pages/examples/markdownPageExample.md
* Update website/src/pages/examples/markdownPageExample.md
* Update website/src/pages/examples/markdownPageExample.md
* Update website/src/pages/examples/markdownPageExample.md
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
This commit is contained in:
parent
592fc48fd3
commit
f234c407f1
15 changed files with 82 additions and 7 deletions
|
@ -8,6 +8,8 @@
|
|||
import globby from 'globby';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import minimatch from 'minimatch';
|
||||
import slash from 'slash';
|
||||
import {
|
||||
encodePath,
|
||||
fileToPath,
|
||||
|
@ -51,6 +53,11 @@ 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',
|
||||
|
||||
|
@ -81,6 +88,7 @@ export default function pluginContentPages(
|
|||
const {baseUrl} = siteConfig;
|
||||
const pagesFiles = await globby(include, {
|
||||
cwd: pagesDir,
|
||||
ignore: options.exclude,
|
||||
});
|
||||
|
||||
function toMetadata(relativeSource: string): Metadata {
|
||||
|
@ -173,12 +181,17 @@ export default function pluginContentPages(
|
|||
// Note that metadataPath must be the same/in-sync as
|
||||
// the path from createData for each MDX.
|
||||
metadataPath: (mdxPath: string) => {
|
||||
const aliasedPath = aliasedSitePath(mdxPath, siteDir);
|
||||
if (excludeRegex.test(slash(mdxPath))) {
|
||||
return null;
|
||||
}
|
||||
const aliasedSource = aliasedSitePath(mdxPath, siteDir);
|
||||
return path.join(
|
||||
dataDir,
|
||||
`${docuHash(aliasedPath)}.json`,
|
||||
`${docuHash(aliasedSource)}.json`,
|
||||
);
|
||||
},
|
||||
forbidFrontMatter: (mdxPath: string) =>
|
||||
excludeRegex.test(slash(mdxPath)),
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue