# Install gatsby
npm install -g gatsby-cli
gatsby new
# Name : kata
# location : default
# CMS : No
# Styling : No
# Additional stuff : Add these both
# * Add markdown Support (Without MDX)
# * Add markdown and MDX support
# Should we do this : y
gatsby develop
Create the markdown directory, with content
src/pages/markdown/first.md
src/pages/markdown/second.md
Routing
Create the file:
Give it the code:
import React from "react"
import { graphql } from "gatsby"
export default function Template({
data,
}) {
const { markdownRemark } = data;
const { html } = markdownRemark;
return (
<div
dangerouslySetInnerHTML={{ __html: html }}
/>
)
}
export const pageQuery = graphql`
query($id: String!) {
markdownRemark(id: { eq: $id }) {
html
}
}
`
Navigate to the markdown pages!
Write the graphql query:
Make the index.js file
Clear out index.js
Add the graphql query
Add the element
Passing props from the query:
Get the files from the props:
Render out those nodes into a list:
Finished example:
export default function Index({data})
{
const { allMarkdownRemark } = data;
const { nodes } = allMarkdownRemark;
const mappedNodes = nodes.map((node, index) => {
const fileName = node.parent.name;
const heading = node.headings[0].value;
return (
<li key={index}>
<a href={fileName}>
heading : {heading}
</a>
</li>
);
});
return (
<div>
<ul>
{ mappedNodes }
</ul>
</div>
);
}