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:
Anshul Goyal 2020-08-06 01:05:55 +05:30 committed by GitHub
parent 592fc48fd3
commit f234c407f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 82 additions and 7 deletions

View file

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