Last active
February 8, 2020 12:16
-
-
Save GarrettWeinberg/e380460e1b55c883cc94011d104b7d8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
backend: | |
name: git-gateway | |
branch: master # Branch to update (optional; defaults to master) | |
media_folder: "src/images" # Media files will be stored in the repo under static/images/uploads | |
collections: | |
- name: "pages" | |
label: "Page" | |
folder: "src/markdown-pages" | |
create: true | |
fields: | |
- {label: "Title", name: "title"} | |
- {label: "Content", name: "content"} | |
- {label: "Slug", name: "slug"} | |
- {label: "Path", name: "path"} | |
- label: "Page Sections" | |
name: "sections" | |
widget: "list" | |
types: | |
- label: "Call To Action" | |
name: "calltoaction" | |
widget: object | |
fields: | |
- {label: "Title", name: "title", widget: "string"} | |
- {label: "Content", name: "content", widget: "markdown", required: false} | |
- {label: "Call to Action Link", name: "link", widget: "string", required: false, hint: "Call to Action Link"} | |
- {label: "Call to Action Text", name: "buttontext", widget: "string", required: false, hint: "Call to Action Text"} | |
- label: "Services" | |
name: "services" | |
widget: object | |
fields: | |
- {label: "Title", name: "title", widget: "string"} | |
- {label: "Content", name: "content", widget: "markdown", required: false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
exports.createPages = ({actions, graphql}) => { | |
const {createPage} = actions; | |
const pageTemplate = path.resolve('src/templates/page.js'); | |
return graphql(`{ | |
allMarkdownRemark { | |
edges { | |
node { | |
id | |
frontmatter { | |
title | |
path | |
sections { | |
buttontext | |
content | |
link | |
title | |
} | |
} | |
} | |
} | |
} | |
}`) | |
.then(result => { | |
if (result.errors) { | |
result.errors.forEach(e => console.error(e.toString())) | |
return Promise.reject(result.errors) | |
} | |
result.data.allMarkdownRemark.edges.forEach(({node}) => { | |
createPage({ | |
path: node.frontmatter.path, | |
component: pageTemplate, | |
context: { | |
id: node.id, | |
} | |
}) | |
}) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import Layout from "../components/layout" | |
import { graphql } from 'gatsby' | |
export default function Template({ data }) { | |
const {markdownRemark: page} = data | |
return ( | |
<Layout> | |
{/* Line Below Works */} | |
<h1>{page.frontmatter.title}</h1> | |
{/* does not work */} | |
<p>{page.frontmatter.sections.title}</p> | |
</Layout> | |
) | |
} | |
export const pageQuery = graphql` | |
query pageByPath($id: String!) { | |
markdownRemark(id: { eq: $id } ) { | |
id | |
frontmatter { | |
path | |
title | |
sections { | |
title | |
} | |
} | |
} | |
} | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment