-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
27 lines (22 loc) · 756 Bytes
/
Copy pathgatsby-node.js
File metadata and controls
27 lines (22 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const multimatch = require('multimatch');
exports.onCreatePage = ({ page, actions, reporter }, options) => {
const { deletePage } = actions;
/** @type {Array.<string>} */
const patterns = options.paths; // this sounds counter-intuitive, but for the end-user `paths` makes the most sense
if (
!patterns ||
!Array.isArray(patterns) ||
!patterns.every(pattern => typeof pattern === 'string')
) {
reporter.panic(
`
"paths" is a required option for gatsby-plugin-exclude, and must be an array of strings.
See docs here - https://github.com/harryparkdotio/gatsby-plugin-exclude
`
);
}
const exclusions = multimatch([page.path], patterns);
if (exclusions.length > 0) {
deletePage(page);
}
};