gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

How can i use 2 createPages api in a gatsby project? because i want to create different pages for each product and different pages for category. #7574

Closed amit-deligence closed 6 years ago

amit-deligence commented 6 years ago

Summary

Relevant information

Environment (if relevant)

File contents (if changed)

gatsby-config.js: N/A package.json: N/A gatsby-node.js: N/A gatsby-browser.js: N/A gatsby-ssr.js: N/A

Manoz commented 6 years ago

I’d say something like this?

const productSet = new Set();
const categorySet = new Set();
const productList = Array.from(productSet);
        productList.forEach((product) => {
          createPage({
            path: `/product/${_.kebabCase(product)}/`,
            component: productPage,
            context: {
              product,
            },
          });
        });

        const categoryList = Array.from(categorySet);
        categoryList.forEach((category) => {
          createPage({
            path: `/categories/${_.kebabCase(category)}/`,
            component: categoryPage,
            context: {
              category,
            },
          });
        });

I'm on my mobile phone right now so it's not that easy to write code but I hope you get the idea. That's how I do it to

shansmith01 commented 6 years ago

Working example here @amit-deligence using datocms as a source https://github.com/shansmith01/mad/blob/master/gatsby-node.js

amit-deligence commented 6 years ago

Thanks @shansmith01 it worked.

amit-deligence commented 6 years ago

@Manoz thanks for your advice