Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout not being used when "/src/layouts" doesn't exist and layout provides by plugin. #4558

Closed
pauldotknopf opened this issue Mar 16, 2018 · 4 comments

Comments

@pauldotknopf
Copy link

I am wrapping my theme/styles/pages/etc in a gatsby plugin.

Inside of my plugin, I create the default ``index``` layout.

export const createLayouts = ({ graphql, boundActionCreators }) => {
    const { createLayout } = boundActionCreators;
    const defaultLayout = slash(path.resolve(path.join(__dirname, 'layouts/index.js')));
    createLayout({
        component: defaultLayout,
        id: 'index',
    })
};

My custom plugin is used, but only if a file matches /src/layouts/index.* exists, like /src/layouts/index.sdfwefw.

I think it may have something to do with this line:

joinPath(store.getState().program.directory, `src/layouts/index.*`)

My requirements require me to have a directory with pure markdown files. I'm building a tool that is geared more towards non-developers. I'd like to avoid having this magical /src/layouts/index.sdfsf existing.

@pauldotknopf
Copy link
Author

Temporary workaround:

export const onCreatePage = ({ page, boundActionCreators }) => {
    const { createPage, deletePage } = boundActionCreators;
    let newPage = page || {};
    if (!newPage.layout) {
        newPage.layout = 'index';
        deletePage(newPage);
        createPage(newPage);
    }
};

@KyleAMathews
Copy link
Contributor

Yeah, we special case src/layouts/index.js as it's so common. What you did in the previous comment is what's required for custom layouts.

@pauldotknopf
Copy link
Author

Maybe you should log if a page doesn't have a layout? Why not always set "index" as the default, and let the cli barf when it tries to use the non-existent layout?

Either way, it isn't good to have imperative magic that depends on something seemingly so unrelated. At least at some logging around it, it would have save me a lot of time.

@KyleAMathews
Copy link
Contributor

Yeah, we're actually removing layouts for v2 as they're kinda problematic for a lot of reasons #3830

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants