Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-page-utils

Package Overview
Dependencies
Maintainers
12
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

  • 0.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
259K
increased by0.03%
Maintainers
12
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 veryfies that it doesn't contains specific characters or strings. It returns true if 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

Keywords

FAQs

Package last updated on 21 Aug 2019

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