fabe/gatsby-universal

Cannot use a page template for multiple Markdown files

chiang-yuan opened this issue · 1 comments

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.

try the createPages function in gatsby-node.js!