2.2.0 • Published 2 months ago

gatsby-page-utils v2.2.0

Weekly downloads
450,295
License
MIT
Repository
github
Last release
2 months ago

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(ObjectStringArray)
2.2.0

2 months ago

2.2.0-next.2

2 months ago

2.2.0-next.1

2 months ago

2.1.2

2 months ago

2.1.1

2 months ago

2.1.3

2 months ago

2.3.0-next.1

2 months ago

2.3.0-next.0

2 months ago

2.2.0-next.0

3 months ago

2.1.0

3 months ago

2.0.0

3 months ago

2.1.0-next.0

3 months ago

2.0.0-zz-next.3

3 months ago

2.0.0-zz-next.2

4 months ago

1.14.0

4 months ago

2.0.0-zz-next.0

4 months ago

2.0.0-zz-next.1

4 months ago

2.0.0-next.2

4 months ago

2.0.0-next.0

4 months ago

2.0.0-next.1

4 months ago

1.14.0-next.2

4 months ago

1.14.0-next.1

5 months ago

1.13.0

5 months ago

1.13.0-next.2

5 months ago

1.14.0-next.0

5 months ago

1.13.0-next.1

5 months ago

1.12.0

5 months ago

1.13.0-next.0

5 months ago

1.12.0-next.3

5 months ago

1.12.0-next.1

6 months ago

1.12.0-next.2

6 months ago

1.11.0

6 months ago

1.12.0-next.0

6 months ago

1.10.0

6 months ago

1.11.0-next.0

6 months ago

1.10.0-next.1

7 months ago

1.9.0

7 months ago

1.10.0-next.0

7 months ago

1.8.0

7 months ago

1.9.0-next.0

7 months ago

1.6.0

8 months ago

1.7.0-next.1

8 months ago

1.7.0-next.2

8 months ago

1.8.0-next.0

8 months ago

1.8.0-next.1

7 months ago

1.7.1

7 months ago

1.7.0

8 months ago

1.4.0-next.3

9 months ago

1.6.0-next.0

9 months ago

1.7.0-next.0

8 months ago

1.5.0

8 months ago

1.4.0

9 months ago

1.5.0-next.0

9 months ago

1.4.0-next.1

9 months ago

1.3.0

9 months ago

1.4.0-next.0

10 months ago

1.3.0-next.1

10 months ago

1.2.0

10 months ago

1.3.0-next.0

10 months ago

1.1.0

10 months ago

1.2.0-next.0

10 months ago

1.1.0-next.2

11 months ago

1.0.0

11 months ago

1.0.0-v3rc.0

11 months ago

1.1.0-next.1

11 months ago

1.1.0-next.0

11 months ago

1.0.0-next.2

11 months ago

0.9.1

11 months ago

1.0.0-next.1

11 months ago

1.0.0-next.0

12 months ago

0.9.0

12 months ago

0.10.0-next.0

12 months ago

0.8.0

12 months ago

0.9.0-next.0

1 year ago

0.7.0

1 year ago

0.8.0-next.0

1 year ago

0.7.0-next.1

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.7.0-next.0

1 year ago

0.6.0-next.1

1 year ago

0.5.0

1 year ago

0.6.0-next.0

1 year ago

0.4.0

1 year ago

0.5.0-next.0

1 year ago

0.3.0

1 year ago

0.4.0-next.0

1 year ago

0.3.0-next.1

1 year ago

0.2.30

1 year ago

0.3.0-next.0

1 year ago

0.2.29

1 year ago

0.2.28

1 year ago

0.2.27

1 year ago

0.2.26

1 year ago

0.2.25

1 year ago

0.2.24

1 year ago

0.2.23

1 year ago

0.2.22

1 year ago

0.2.21

1 year ago

0.2.20

1 year ago

0.2.19

1 year ago

0.2.18

1 year ago

0.2.17

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.45

2 years ago

0.0.44

2 years ago

0.0.43

2 years ago

0.0.42

2 years ago

0.0.40

2 years ago

0.0.41

2 years ago

0.0.39

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.36

2 years ago

0.0.35

2 years ago

0.0.33

2 years ago

0.0.32

2 years ago

0.0.31

2 years ago

0.0.30

2 years ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago