Socket
Socket
Sign inDemoInstall

gatsby-page-utils

Package Overview
Dependencies
Maintainers
19
Versions
387
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


Version published
Weekly downloads
276K
increased by2.2%
Maintainers
19
Weekly downloads
 
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

FAQs

Package last updated on 07 Sep 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc