gatsby-page-utils
Gatsby library that helps creating pages
Last updated 7 days ago by mxstbr .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gatsby-page-utils 
SYNC missed versions from official npm registry.

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

property description type
path Directory path in which pages are stored String
glob A glob that select files to watch String
onNewFile A function called each time a new file is added Function
onRemovedFile A function called each time a file is removed Function

createPath

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

property description type
path File path String

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.

property description type
path File path String

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.

property description type
path File path String
ignore A pattern to match with file path (Object | String | Array)

Current Tags

  • 0.0.38-berry-mdx.56                                ...           berry-mdx (4 months ago)
  • 0.2.7                                ...           latest (7 days ago)
  • 0.0.13-otp-test.31                                ...           otp-test (9 months ago)
  • 0.1.2-prompt-restart.146                                ...           prompt-restart (9 days ago)

62 Versions

  • 0.2.7                                ...           7 days ago
  • 0.2.6                                ...           8 days ago
  • 0.2.5                                ...           8 days ago
  • 0.2.4                                ...           9 days ago
  • 0.1.2-prompt-restart.146                                ...           9 days ago
  • 0.2.3                                ...           10 days ago
  • 0.1.2-prompt-restart.133                                ...           13 days ago
  • 0.1.2-prompt-restart.132                                ...           13 days ago
  • 0.1.2-prompt-restart.128                                ...           13 days ago
  • 0.2.2                                ...           15 days ago
  • 0.2.1                                ...           23 days ago
  • 0.2.0                                ...           a month ago
  • 0.1.4                                ...           a month ago
  • 0.1.3                                ...           a month ago
  • 0.1.2                                ...           a month ago
  • 0.1.1                                ...           2 months ago
  • 0.1.0                                ...           2 months ago
  • 0.0.45                                ...           2 months ago
  • 0.0.44                                ...           3 months ago
  • 0.0.43                                ...           3 months ago
  • 0.0.42                                ...           3 months ago
  • 0.0.41                                ...           3 months ago
  • 0.0.40                                ...           3 months ago
  • 0.0.39                                ...           4 months ago
  • 0.0.38                                ...           4 months ago
  • 0.0.38-berry-mdx.56                                ...           4 months ago
  • 0.0.37                                ...           5 months ago
  • 0.0.36                                ...           5 months ago
  • 0.0.35                                ...           6 months ago
  • 0.0.33                                ...           6 months ago
  • 0.0.32                                ...           6 months ago
  • 0.0.31                                ...           6 months ago
  • 0.0.30                                ...           6 months ago
  • 0.0.29                                ...           7 months ago
  • 0.0.28                                ...           7 months ago
  • 0.0.27                                ...           7 months ago
  • 0.0.26                                ...           7 months ago
  • 0.0.25                                ...           8 months ago
  • 0.0.24                                ...           8 months ago
  • 0.0.23                                ...           8 months ago
  • 0.0.21                                ...           8 months ago
  • 0.0.20                                ...           8 months ago
  • 0.0.19                                ...           8 months ago
  • 0.0.18                                ...           8 months ago
  • 0.0.17                                ...           9 months ago
  • 0.0.16                                ...           9 months ago
  • 0.0.15                                ...           9 months ago
  • 0.0.14                                ...           9 months ago
  • 0.0.13                                ...           9 months ago
  • 0.0.13-otp-test.31                                ...           9 months ago
  • 0.0.13-otp-test.30                                ...           9 months ago
  • 0.0.12                                ...           9 months ago
  • 0.0.11                                ...           9 months ago
  • 0.0.10                                ...           9 months ago
  • 0.0.9                                ...           9 months ago
  • 0.0.8                                ...           9 months ago
  • 0.0.7                                ...           9 months ago
  • 0.0.6                                ...           9 months ago
  • 0.0.5                                ...           10 months ago
  • 0.0.4                                ...           a year ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago

Copyright 2014 - 2017 © taobao.org |