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

[1.0] Use index.md as text body in index.js #573

Closed
iiroj opened this issue Nov 25, 2016 · 1 comment
Closed

[1.0] Use index.md as text body in index.js #573

iiroj opened this issue Nov 25, 2016 · 1 comment

Comments

@iiroj
Copy link

iiroj commented Nov 25, 2016

It would be nice if I could have both index.js and index.md in the same path and then import the Markdown into my index. This way I could have one-off "layouts" for routes written in JSX while still having a block of text written in Markdown.

I want to do something like this in my index.js:

import { frontmatter, htmlBody } from 'index.md'
…
<Helmet title={frontmatter.title} />
…
<article dangerouslySetInnerHTML={{ __html: htmlBody }} />

What do you think? I assume it would be simple to support this with a Webpack loader. React-static-boilerplate uses this.

@KyleAMathews
Copy link
Contributor

You can actually do basically this already :-)

Gatsby 0.x uses loaders to pull in Markdown, etc. All page data is passed into every js page as a prop e.g. https://github.com/gatsbyjs/gatsby-starter-blog/blob/master/pages/index.js#L16

So you could either just use the data passed in as props or you could import the data directly.

In 1.x, you'll be able to query individual files using graphql doing something like (exact API in flux still):

{
  file(resolve: "./index.md") {
    Markdown {
      frontmatter {
        title
        author
      }
      html
    }
  }
}

Lots more about the new GraphQL stuff here if you're interested: #420

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