ChristopherBiscardi / gatsby-theme-examples

Examples of using gatsby themes
141 stars 11 forks source link

index.js – 404.js in package #3

Closed signalwerk closed 5 years ago

signalwerk commented 6 years ago

Is there a way to get index.js and 404.js from the theme

ChristopherBiscardi commented 6 years ago

index.js (and any page created by the page creator plugin) is achievable by using another instance of the page creator plugin in the theme as seen in this commit I just pushed. The important part of the config is that the instance of the page creator plugin points at the theme's src/pages instead of the site's.

// theme's gatsby-config
    {
      resolve: `gatsby-plugin-page-creator`,
      options: {
        path: require.resolve(`./src/pages`),
      },
    },

You can also use the same approach for markdown pages, etc. (adding another instance of the relevant plugin, such as the filesystem source.


For 404s, the situation seems a bit more complicated and I'm not sure why the theme's 404 isn't showing up. There are two internal plugins for handling development and production 404s which I didn't see an obvious reason in. We'll have to look into this a bit more.

pgegenfurtner commented 5 years ago

It seems this doesn't work anymore? I added the plugin like in your commit, but the pages don't get created.

ChristopherBiscardi commented 5 years ago

@pgegenfurtner can you be more specific? which pages don't get created, how is your config set up, etc.

pgegenfurtner commented 5 years ago

It was a wrong config on my side. My theme is extracted into a npm package.

{
      resolve: `gatsby-plugin-page-creator`,
      options: {
        path: require.resolve(`/src/pages`),
      },
    },

didn't work. If I point the path to the theme page directory via

{
      resolve: `gatsby-plugin-page-creator`,
      options: {
        path: (`${__dirname}/src/pages`),
      },
    },

it works.

maecapozzi commented 5 years ago

@ChristopherBiscardi - how do you feel about closing this issue? Looks like it has been resolved?

ChristopherBiscardi commented 5 years ago

yep, closing. Thanks for the ping :)