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

Cannot use a page template for multiple Markdown files #69

Open
chiang-yuan opened this issue Jul 24, 2020 · 1 comment
Open

Cannot use a page template for multiple Markdown files #69

chiang-yuan opened this issue Jul 24, 2020 · 1 comment

Comments

@chiang-yuan
Copy link

chiang-yuan commented Jul 24, 2020

When I try to create a page template for multiple Markdown files as described in Gatsby's docs, the page template raises the following warning:

The GraphQL query in the non-page component "C:/Users/qaqow/Documents/Portfolio/src/templates/post-template.js"
Exported queries are only executed for Page components. It's possible you're
trying to create pages in your gatsby-node.js and that's failing for some
reason.

If the failing component(s) is a regular component and not intended to be a page
component, you generally want to use a <StaticQuery> (https://gatsbyjs.org/docs/static-query)
instead of exporting a page query.

If you're more experienced with GraphQL, you can also export GraphQL
fragments from components and compose the fragments in the Page component
query and pass data down into the child component — https://graphql.org/learn/queries/#fragments

Even though I can successfully query data using GraphQL code:

{
  allMarkdownRemark {
    nodes{
      html
      frontmatter {
        date(formatString: "MMMM DD, YYYY")
        slug
        title
      }
    }
  }
}

, I want to follow another starter by alxshelepenok to create pages file-by-file. However, no markdown page is returned and shown on the site map.

export const pageQuery = graphql`
  query PostBySlug($slug: String!) {
    markdownRemark(frontmatter: { slug: { eq: $slug } }) {
      html
      frontmatter {
        date(formatString: "MMMM DD, YYYY")
        slug
        title
      }
    }
  }
`

I am new to React/Gatsby and have fairly limited experience in web development and JS. Is there anybody can help me with this? The repo of my site is here. Thanks.

@knhn1004
Copy link

try the createPages function in gatsby-node.js!

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