How to use the gatsby-page-utils.watchDirectory function in gatsby-page-utils

To help you get started, we’ve selected a few gatsby-page-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github karolis-sh / gatsby-mdx / packages / gatsby-transformer-mdx / gatsby / create-pages-statefully.js View on Github external
module.exports = async ({ store, actions }, pluginOptions) => {
  const { pagesPath } = getOptions(pluginOptions);
  const { createPage, deletePage } = actions;

  const pagesDirectory = path.resolve(process.cwd(), pagesPath);
  const pagesGlob = '**/*.mdx';
  const pageCreator = new PageCreator({ pagesDirectory, store, createPage, deletePage });

  const files = await glob(pagesGlob, { cwd: pagesPath });
  await Promise.all(files.map(file => pageCreator.create(file)));

  await watchDirectory(
    pagesPath,
    pagesGlob,
    addedPath => pageCreator.create(addedPath),
    removedPath => pageCreator.remove(removedPath)
  );
};

gatsby-page-utils

Gatsby library that helps creating pages

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis