Skip to content

Instantly share code, notes, and snippets.

@isNan909
Created August 14, 2020 11:04
Show Gist options
  • Select an option

  • Save isNan909/75e15a4329704d659e31974240112103 to your computer and use it in GitHub Desktop.

Select an option

Save isNan909/75e15a4329704d659e31974240112103 to your computer and use it in GitHub Desktop.
Creating template with the contentful data
import React from "react"
import { Link, graphql } from "gatsby"
import Layout from "../components/layout"
import SEO from "../components/seo"
const SitePosts = ({ data }) => {
const { heading, subheading, description, image } = data.contentfulSitePost
return (
<Layout>
<SEO title={heading} />
<div className="ourpost">
<h1>{heading}</h1>
<img alt={title} src={image.file.url} />
<h3>{subheading}</h3>
<p>{description.content.content.value}</p>
<Link to="/siteposts">View more posts</Link>
<Link to="/">Back to Home</Link>
</div>
</Layout>
)
}
export default SitePosts
export const pageQuery = graphql`
query($slug: String!) {
contentfulSitePost(slug: { eq: $slug }) {
heading
subheading
slug
description {
content {
content {
value
}
}
}
image {
file {
url
}
}
}
}
`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment