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

@leonardodino/gatsby-plugin-page-creator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leonardodino/gatsby-plugin-page-creator

Gatsby plugin that automatically creates pages from React components in specified directories

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

gatsby-plugin-page-creator

Gatsby plugin that automatically creates pages from React components in specified directories. Gatsby includes this plugin automatically in all sites for creating pages from components in src/pages.

With this plugin, any file that lives in the src/pages folder (or subfolders) will be expected to export a React Component to generate a Page. The following files are automatically excluded:

  • template-*
  • __tests__/*
  • *.test.jsx?
  • *.spec.jsx?
  • *.d.tsx?
  • *.json
  • *.yaml
  • _*
  • .*

Install

npm install --save gatsby-plugin-page-creator

How to use

// gatsby-config.js

module.exports = {
  plugins: [
    // You can have multiple instances of this plugin
    // to create pages from React components in different directories.
    //
    // The following sets up the pattern of having multiple
    // "pages" directories in your project
    {
      resolve: `gatsby-plugin-page-creator`,
      options: {
        path: `${__dirname}/src/account/pages`,
      },
    },
    {
      resolve: `gatsby-plugin-page-creator`,
      options: {
        path: `${__dirname}/src/settings/pages`,
      },
    },
    // You can also provide "createPath" and "validatePath" functions
    // to override default behaviour, if needed
    {
      resolve: `gatsby-plugin-page-creator`,
      options: {
        path: `${__dirname}/src/articles`,
        createPath: (basePath, filePath) => {
          // Creates a custom URL based on filename
          return `/articles/${slugify(basename(filePath))}/`
        },
        validatePath: (relativePath, isValid) => {
          // Filter page creation based on criteria,
          // the second argument is the default validatePath function
          if (!isValid(relativePath)) return false
          if (basename(relativePath).startsWith("draft-")) return false
          return true
        },
      },
    },
  ],
}

Keywords

gatsby

FAQs

Package last updated on 10 Jan 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