Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

gatsby-page-utils

Package Overview
Dependencies
Maintainers
5
Versions
392
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-page-utils

Gatsby library that helps creating pages

latest
Source
npmnpm
Version
3.15.0
Version published
Maintainers
5
Created
Source

gatsby-page-utils

Usage

npm install gatsby-page-utils

Example

const {
  createPath,
  ignorePath,
  validatePath,
  watchDirectory,
} = require(`gatsby-page-utils`)

// ...

const pagesDirectory = "/pages"
watchDirectory(
  pagesDirectory,
  "**/*.{js, jsx}",
  addedPath => {
    // Filter out special components that shouldn't be made into
    // pages.
    if (!validatePath(addedPath)) {
      return
    }

    // Filter out anything matching the given ignore patterns and options
    if (ignorePath(addedPath, "*/connexion")) {
      return
    }

    // Create page object
    const createdPath = createPath(addedPath)
    const page = {
      path: createdPath,
      component: systemPath.join(pagesDirectory, addedPath),
    }

    // Add page
    createPage(page)
  },
  removedPath => {
    // Delete the page for the now deleted component.
    const componentPath = systemPath.join(pagesDirectory, removedPath)
    store.getState().pages.forEach(page => {
      if (page.component === componentPath) {
        deletePage({
          path: createPath(removedPath),
          component: componentPath,
        })
      }
    })
  }
)

watchDirectory

Watch activity on a directory and call functions each time a file is added or removed

propertydescriptiontype
pathDirectory path in which pages are storedString
globA glob that select files to watchString
onNewFileA function called each time a new file is addedFunction
onRemovedFileA function called each time a file is removedFunction

createPath

Create a page path from a file path. It returns the page path.

propertydescriptiontype
pathFile pathString

validatePath

Validate a file path. It verifies that the path doesn't contain specific characters or strings. It returns true if the path is valid otherwise it returns false.

propertydescriptiontype
pathFile pathString

ignorePath

Determines if path should be ignored regarding of a ignore pattern passed as parameter. It returns true if the passed path should be ignored otherwise it returns false.

propertydescriptiontype
pathFile pathString
ignoreA pattern to match with file path(Object | String | Array)

Keywords

gatsby

FAQs

Package last updated on 27 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts